Skip to content

Tag: sql

Reuse select aliases in MySQL

I currently have a query where I’m doing two subqueries to get X, Y data: Y is kind of subset of X, since I apply just an additional condition to the existing ones, if X is: Then Y has an additional AND condition: And for the value of X I need to take those two results – X and Y

Count of values grouped by a row id

My data looks like the below, I want to sum up the count of occurrences of ALL. This should be grouped by Id. So the output should look like, My query looks like, This query is giving me the result as, which is incorrect for Id 2. The value for Friday for the second row is an empty string. dbfiddle

Returning Null Value – Coalesce and ISNULL

I may be having a brain fog, but if I have below: Which gives me the value of invalid for all fields in my info column that have an empty space, if I used ISNULL instead of COALESCE would it give me the same result? I cannot access a sql engine currently so just wanted to sanity check. Thanks! Answer

Migrate columns to JSON in SQL

I have a table (Table A) that looks like this: I want to convert it to a table (Table B) like this How do you insert/transform into a json column? Or do I just have to construct the json string myself? Additionally, does the nullableness of the int columns affect creation? Are clicks for example not included …

Select from dynamic table

I need to run a query in sql that depending on the month and year I need to call a different table. For example: If current_date is 31/08/2020, execute: select * from table_ago If current_date is 01/09/2020, execute: select * from table_sep Is it posible using a query in SQL Server? Answer You can use a store…