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 |
|
black_pearl
Starting Member
15 Posts |
Posted - 2006-05-14 : 20:51:09
|
hello, i have a table here:serial__________code5U0604T01561| 3607.05U0604T01561| 0.05U0604T01561| 0.05U0604T01728| 0.05U0604T01728| 0.05U0604T01736| 0.0how can i select the serial which has a code 0.0 and has a dulpicate but its duplicate is also code 0.0, not a nonzero.for example: i want to select the serial 5U0604T01728 because it appeared twice and both codes are 0.0. but i dont want to select the serial 5U0604T01561 because though it appeared many times and two of their codes are 0.0, one was a nonzero. pls help me with my query. hope my explaination wasnt confusing. thanks a lot. __black_pearl__ |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-05-14 : 22:41:53
|
| [code]DECLARE @table TABLE(serial VARCHAR(55), code DECIMAL(6,1))INSERT @table(serial, code) SELECT '5U0604T01561','3607.0' UNION ALL SELECT '5U0604T01561','0.0' UNION ALL SELECT '5U0604T01561','0.0' UNION ALL SELECT '5U0604T01728','0.0' UNION ALL SELECT '5U0604T01728','0.0' UNION ALL SELECT '5U0604T01736','0.0'SELECT serial, code FROM @tableSELECT t.serialFROM @table t LEFT OUTER JOIN ( SELECT serial FROM @table WHERE code <> 0.0) dt ON t.serial = dt.serialWHERE dt.serial IS NULLGROUP BY t.serial, t.codeHAVING COUNT(t.serial)>1 [/code]MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-05-14 : 23:24:04
|
| [code]Select serialfrom MyTablegroup by serialhaving count(*) > 0 and min(code) = 0.0 and max(code) = 0.0[/code]CODO ERGO SUM |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-05-15 : 00:46:53
|
:)MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
black_pearl
Starting Member
15 Posts |
Posted - 2006-05-15 : 21:51:36
|
thanks,guys! great help! __black_pearl__ |
 |
|
|
|
|
|
|
|