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
Tag: sql
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
Is there a way to separate query results in SQL Server Management Studio (SSMS)?
I got a simple query which return a results from an OrderLine table. Is there a way to visually separate the query results to make it easier to read, like in the image shown here? Results: Answer
Access – Add Left Join to Return Value Based on Primary Key (PK)
I need help querying a user name based on its primary key value in table. Another user @gordon-linoff helped me create a query to pull the most recent NoteDate for every OpportunityID in a table. I …
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 …
Split value into multiple rows
The following are two tables I have in the database mavenmovies. testLocation (TABLE 1) CREATE TABLE mavenmovies.testLocation ( id INT AUTO_INCREMENT PRIMARY KEY, State varchar(255), name …
count distinct if a condition is satisfied
I have a table which shows if a address_no has a telephone or not. To determine, i am looking at cell_phone and house_phone columns and want to write ‘no phone’ only when house_phone and cell_phone is …
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…
Auto increment temporary column in select statement MySQL 8
Hello i use this type of sentence to return an auto increment column in my prepared statement selects cnt := cnt + 1 SET @query = CONCAT(‘SELECT * FROM (SELECT (@cnt := @cnt + 1) AS id, a….