Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
satheesh
Posting Yak Master
152 Posts |
Posted - 2013-03-15 : 13:03:58
|
Dear All,I have a table which has policy id and age of the traveler in separate field.Max 7 travelerI need to select all the policyid which has only 1 adult traveler (18yrs or above)for exPolicyid t1 t2 t3 t4 t5 t6 t71123 12 8 5 7 45 2345 56 673234 9 356785 56 58 132456 23 11 14Result112332342456Any help will be highly appreciated!ThanksSG |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-15 : 13:09:54
|
[code]SELECT policyidFROM table tunpivot (Age FOR traveller IN ([t1],[t2],[t3],[t4],[t5],[t6],[t7]))ugroup by policyidhaving sum(case when Age > 18 then 1 else 0 end) = 1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
satheesh
Posting Yak Master
152 Posts |
Posted - 2013-03-18 : 12:46:15
|
Its working.Many Thanks Visakh. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-18 : 12:49:10
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|