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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Count Distinct Rows

Author  Topic 

kohlhaas77
Starting Member

25 Posts

Posted - 2009-07-08 : 13:20:48
Iyou need to get a count of distinct rows by say, 4 variables, how would you do that? I have "SELECT COUNT(DISTINCT AMISYS__ID, TIN, EFF_DT, CAN_DT) FROM NHP_Facets_Phase_1_PhyCount", but I get an error on the commas

Dan Kohlhaas

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 13:28:16
do you mean this?
SELECT COUNT(1) FROM (SELECT AMISYS__ID, TIN, EFF_DT, CAN_DT FROM NHP_Facets_Phase_1_PhyCount GROUP BY AMISYS__ID, TIN, EFF_DT, CAN_DT)t
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 13:29:07
or this?

SELECT AMISYS__ID, TIN, EFF_DT, CAN_DT , COUNT(PKCol)FROM NHP_Facets_Phase_1_PhyCount 
GROUP BY AMISYS__ID, TIN, EFF_DT, CAN_DT


where PKCol is your primary key column
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-08 : 13:30:28
SELECT AMISYS__ID, TIN, EFF_DT, CAN_DT, COUNT(*)
FROM FROM NHP_Facets_Phase_1_PhyCount
GROUP BY AMISYS__ID, TIN, EFF_DT, CAN_DT

EDIT: dang too slow.. :)
Go to Top of Page
   

- Advertisement -