SQLPuzzle

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Question

Write a T-SQL which will give us records where we have at least 1 different color
for the entire group. Columns to be fetched are GroupId, ProductId & Color.
Rule(s)

Reply me with your solution before 4:30 PM.


Temp Tables, Table Variables and CTEs are not allowed. No loops
please.
Your solution should work on SQL Server 2012.
In case of tie, winner will be decided via better execution plan !.

Script

--

CREATE TABLE Colors


(
GroupID INT
, ProductID INT
, Color VARCHAR(30)
)
GO
INSERT INTO Colors VALUES
( 1,
300
,'Blue'),
( 1,
391
,'Blue'),
( 1 ,
237
,'Yellow'),
( 2 ,
100
,'Black'),
( 3 ,
500
,'Green'),
( 3 ,
501
,'Green'),
( 4 ,
921
,'Blue'),
( 4 ,
834
,''),
( 4 ,
512
,'Red')
GO
--

You might also like