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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with a query - count(distinct x)

Status
Not open for further replies.

cfw2

Technical User
Mar 18, 2005
18
US
I am trying to perform a count distinct, however I would like to count a distinct grouping of columns like so:

select
count(distinct field1)
,count( distinct field1, field2)
from x

anyone have any ideas?

thank you,
cfw2
 
How about this:
Code:
select count(distinct field1), count(*)
from
(	select distinct field1, field2
	from myTable
) X
If you want to ignore rows for which field2 is NULL, replace "*" with "field2"


------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top