Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count multiple columns 1

Status
Not open for further replies.
Nov 7, 2002
61
US
Hi,

I have a table that looks like this:

AdmitDate AcctNum
2005-03-04 5713513
2005-05-11 5713683
2005-05-18 5714069
2005-06-01 5714138
2005-06-03 5714152
2005-06-05 5714153
2005-06-05 5711825

I want to be able to count by both distinct AcctNum AND AdmitDate, because there will be some duplicate AcctNums for the same AdmitDate and some duplicate AcctNums with different AdmitDates. So in other words, I want a count of each unique AcctNum for each AdmitDate.

I tried this:

Code:
select count(DISTINCT(AcctNum, AdmitDate)) from KnownMedicaid

...but got an error message saying that COUNT can't be used with more than one column.

Any help would be greatly appreciated.

Thanks,
Mike
 
Did you try this.
Code:
select DISTINCT count(AcctNum) 
from KnownMedicaid
GROUP BY AdmitDate

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
one way....

Code:
Select Count(*)
From   (
       select DISTINCT AcctNum, AdmitDate 
       from KnownMedicaid
       ) as A

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
select count(*) from
(select AcctNum, AdmitDate
from KnownMedicaid
group by AcctNum, AdmitDate) z


example
Code:
create table bla (col1 int,col2 int)

insert bla values(1,1)
insert bla values(1,1)
insert bla values(2,2)
insert bla values(3,1)

select count(*) from(
select * from bla
group by col1,col2) z

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
Google Interview Questions





 
Sorry about that.

I miss understood when you said. " I want a count of each unique AcctNum for each AdmitDate."

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top