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 |
matrixrep
Starting Member
30 Posts |
Posted - 2011-07-14 : 10:04:02
|
Hi all,I have the following table:Item Type Kind---- ---- ----1 a P1 b P1 a M2 c P2 d P2 c M2 d M3 e T3 f POn column Item, For 1, when the number of P is not equal the number of M in the column Kind , it is okay. For 2, when the number of P is equal the number of M in the column Kind, i want item 2 out. For 3, since there is a kind T, i want item 3 out,So at the end i will have, Item Type Kind---- ---- ----1 a P1 b P1 a MI have thousand of rows like that.Any suggestion would be deeply appreciated. |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-07-14 : 11:02:03
|
Try thisselect item from tablegroup by itemhaving sum(case when kind in ('M','P') then 1 else -100 end)%2=1MadhivananFailing to plan is Planning to fail |
 |
|
matrixrep
Starting Member
30 Posts |
Posted - 2011-07-14 : 13:46:50
|
it is exactly what i was looking for with a little bit of change.Thank you |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-07-14 : 14:14:03
|
quote: Originally posted by matrixrep it is exactly what i was looking for with a little bit of change.Thank you
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|