question

AlexKlap avatar image
AlexKlap asked

Check 0 in a group

Hello All, Is it possible to check whether group of prod,size and cost does not have atleast 1 white color. and can we retain all columns in output (prod,size,cost,nos,color) Prod |size|cost|nos|color Wrangler|L |150$|1 |BLUE Wrangler|L |150$|1 |BLUE Wrangler|L |150$|1 |BLUE Wrangler|L |225$|1 |BLUE Wrangler|XL |225$|1 |BLACK Wrangler|XL |225$|1 |BLACK Wrangler|XL |225$|1 |WHITE Wrangler|XL |225$|1 |WHITE Wrangler|XL |225$|1 |BLUE Wrangler|XL |450$|1 |BLACK Wrangler|XL |450$|1 |BLACK Wrangler|XL |450$|1 |BLACK Wrangler|XL |450$|1 |WHITE Wrangler|XL |450$|1 |WHITE **Output:** **Prod |size|cost|nos|color Wrangler|L |150$|1 |BLUE Wrangler|L |150$|1 |BLUE Wrangler|L |150$|1 |BLUE Wrangler|L |225$|1 |BLUE** as it does not contain atleast 1 white. Please share your view. Thank You Very Much
sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
iainrobertson avatar image
iainrobertson answered
Something like: select Prod, size, cost, nos from MyTable t where not exists ( select 'has white' from MyTable where Prod = t.Prod and size = t.size and cost = t.cost and colour = 'WHITE' ) Should do the trick
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
maybe with a where clause COLOR = 'White' somewhere? :)
1 Like 1 ·
iainrobertson avatar image iainrobertson commented ·
Just checking that you're paying attention of course... \*Cough, cough\*
1 Like 1 ·
AlexKlap avatar image AlexKlap commented ·
speechless!! in front of two genius. Thank You
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.