Tags
A puzzle, A quick query puzzle, A SQL Puzzle, A SQL Server Puzzle, Complex SQL Challenges, complex sql statement(puzzle), Complex TSQL Challenge, Interesting Interview Questions, Interview Qs.SQL SERVER Questions, Interview questions on Joins, Interview Questions on SQL, InterviewQuestions, InterviewQuestions for SQL, Joins, Joins Interview questions, Joins Puzzle, Khowal, Learn complex SQL, Learn SQL, Learn T-SQL, Objective Puzzle, Pawan, Pawan Khowal, Pawan Kumar, Pawan Kumar Khowal, PL/SQL Challenges, puzzle sql developer, Puzzles, Puzzles in SQL, PUzzles in SQL SERVER, Queries for SQL Interview, SELECT, SELECT Puzzle, Some useful SQL puzzles to teach SQL, SQL, SQL 2012, SQL 2014, SQL 2014 Interview Questions, SQL Challenge, SQL Challenges, SQL Interview Questions, SQL Joins, SQL pl/sql puzzles, SQL puzzle, SQL Puzzles, SQL Queries, SQL QUERY PUZZLES, SQL Quiz, SQL Server Database, SQL SERVER Interview questions, SQL Server Puzzle, SQL SERVER Puzzles, SQL Skills, SQL Sudoku, SQL Top clause, SQL Tricky Puzzles, SQL Trikcy question, sql/database interview for puzzle sql developer, SQLSERVER, T SQL Puzzles, T-SQL Challenge, The Biggest Gap Puzzle, The Gap Puzzle, The GroupBy Puzzle, Tough SQL Challenges, Tough SQL Puzzles, Tricky Puzzles in SQL, tricky puzzles in SQL Server, Tricky Questions, TSQL, TSQL Challenge, TSQL Challenges, TSQL Interview questions, TSQL Puzzles, TSQL Queries, TSQLPuzzles, Week puzzle
T-SQL Output Query | [ The Null Puzzle ]
Please go through the query and the sample input data and provide the output of the query written below-
-- CREATE TABLE testNULLsHere ( ID SMALLINT ,VALUE SMALLINT ) GO INSERT INTO testNULLsHere VALUES (1,10),(2,NULL),(1,50),(2,NULL),(3,NULL) GO --
Data
ID | VALUE |
1 | 10 |
2 | NULL |
1 | 50 |
2 | NULL |
3 | NULL |
PUZZLE 1 – What will be the output of this query
-- SELECT ID , SUM(VALUE) FROM testNULLsHere GROUP BY ID --
Let’s insert some data into the existing table
-- INSERT INTO testNULLsHere VALUES (2,0),(3,NULL),(3,0) GO --
Data
ID | VALUE |
1 | 10 |
2 | NULL |
1 | 50 |
2 | NULL |
3 | NULL |
2 | 0 |
3 | NULL |
3 | 0 |
PUZZLE 2 – What will be the output of this query
-- SELECT ID , SUM(VALUE) FROM testNULLsHere GROUP BY ID --
Please leave a comment if you need solution to the above puzzle
Keep Learning
Pawan Kumar Khowal
MSBISKills.com