mysql get count(column) if first select query return no result
I want to execute 2nd query if first query return no result. I want to get those id age > 20. If no result, want to get number of id with age < 20. In table: id name gender age…
I want to execute 2nd query if first query return no result. I want to get those id age > 20. If no result, want to get number of id with age < 20. In table: id name gender age…
I want it to match only if the number B is not inside a bigger number. e.g. I dont want it to match this: A = "12345" B = 234 I want it to match this: A = "94, 234,…
How do I sum the count of populated fields. An example of the data. The desired output would be. This is what I have managed so far. select m.project_ref, ( select count(*) from (values (m.[EWI/IWI]), (m.Glazing), (m.Solar), (m.CWI), (m.Boiler), (m.TRV),…
i have a really complicated SQL query with alots of where conditions (all are ands) and i have some data. Sometimes some entries are not fetched when executing the sql query, which is fine and expected. But from a business…
Query: INSERT INTO derived (a, b, c) VALUES (?, ?, ?) ON CONFLICT (a, b, c) DO UPDATE SET a = EXCLUDED.a, b = EXCLUDED.b, c = EXCLUDED.c WHERE EXISTS (select a from primary where a = ?) Please note,…
I'm new to SQL and don't think I understand how to write if else statements. The following code block produces a syntax error at the if statement. create or replace function weight_from_days_ago (days_ago int, difficulty int, user_level int, root_score int)…
I need to write a function that will transform the results of a column called "store_id" in a table. I want to transform the integer 1 into "Store 1" and 2 into "Store 2", but I get errors no matter…
I apologize in advance, I am certainly not a db expert, so might be asking something obvious here. I have a large postgreql table with the following (example) data : CREATE TABLE t (ID int, componentid varchar(30), scanresult varchar(30), eventdatetime…
I have a table called cc_index and the table has among others the following columns: length, date, url, [other_colums]. The same url may appear in multiple rows. For each url, I only want to retain a single row (but all…
In my PostgreSQL 14.8 database I have a table named orders that looks as follows: CREATE TABLE orders ( user_id int , order_id int , order_date date , quantity int , revenue float , product text ); INSERT INTO orders…