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 |
|
plaidoe
Starting Member
4 Posts |
Posted - 2008-09-09 : 11:34:20
|
Does anyone how to do a distinct count of 2 attributes from the same table?For example:SELECT COUNT (UNIQUE ord_id),COUNT(UNIQUE cust_id)FROM OrdersThank you! |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-09-09 : 11:37:01
|
| UNIQUE => DISTINCT |
 |
|
|
plaidoe
Starting Member
4 Posts |
Posted - 2008-09-09 : 11:43:08
|
| Sorry I'm not sure what UNIQUE => DISTINCT means.I get a syntax error msg when I run the example in original post. Is there another way to write this query to make it run? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-09 : 11:45:37
|
Bjoerns told you how to make your query work...SELECT COUNT (DISTINCT ord_id), COUNT(DISTINCT cust_id)FROM Orders E 12°55'05.63"N 56°04'39.26" |
 |
|
|
plaidoe
Starting Member
4 Posts |
Posted - 2008-09-09 : 11:50:42
|
| I see. I tried it and it didn't work. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-09 : 12:03:11
|
And why do you think it doesn't work?Do you get an error? No records? To many records? Wrong kind of records? A dent in your computer screen?Printer fire? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-09-09 : 12:04:00
|
| [code]create table #table( i1 int, i2 int)insert into #tableselect 1, 1 union allselect 1, 2 union allselect 3, 3 union allselect 4, 2select count(distinct i1), count(distinct i2)from #table[/code]gives both 3 to me... |
 |
|
|
plaidoe
Starting Member
4 Posts |
Posted - 2008-09-09 : 12:05:15
|
| [Error Code: -201, SQL State: 42000] A syntax error has occurred. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-09 : 12:26:16
|
Are you REALLY sure you are using MICROSOFT SQL Server 2005? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|