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 |
|
DSullSQL
Starting Member
3 Posts |
Posted - 2012-02-17 : 09:52:21
|
| Hi I am trying to run a query against data that is somewhat like thisAcct_NO Type1 BIG1 BIG1 BIG1 BIG2 BIG2 SMALL3 SMALL3 SMALL3 SMALL3 SMALL3 BIG4 BIG4 BIG4 BIG4 BIG5 SMALL5 SMALL5 SMALL5 SMALL6 BIG6 BIG6 BIG6 BIG6 SMALL6 SMALLAs you can see some of the repeating accnt_no values have both BIG and SMALL types associated with them. What I want to do is write a query to count the number of unique account numbers that have both BIG and Small types associated with them.Thanks,D |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-17 : 13:15:25
|
| [code]SELECT COUNT(DISTINCT Accnt_No) AS CntFROM(SELECT Acct_NOFROM tableGROUP BY Acct_NOHAVING COUNT(DISTINCT CASE WHEN Type IN ('BIG','SMALL') THEN 1 ELSE NULL END) = 2)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|