Sunday, March 25, 2012

count from distinct

Hello

for mS SQL 2000

with

SELECT DISTINCT Name, Region
FROM Groups
GROUP BY Name, Region

I get 254 rows

but how can I get the COUNT only ?

something like

SELECT COUNT(SELECT DISTINCT Name, Region
FROM Groups
GROUP BY Name, Region) AS CPT FROM Groups

i must get 254

thank you for helpingsChange query according to your requirement...

USE Pubs

select count (*) as row_count from (select type, pub_id from titles group by type, pub_id) t

select type, pub_id from titles group by type, pub_id|||it works perfetly

thanks a lot Rajesh Patel|||Que?

SELECT COUNT(DISTINCT Name, Region)
FROM Groups

Doesn't work?

EDIT: No it doesn't...but

USE Northwind
GO
SELECT COUNT(DISTINCT CustomerID+CONVERT(varchar(10),EmployeeID)) FROM Orders

Does|||i'm liking rajesh's solution way more, brett ;)sql

No comments:

Post a Comment