TSQL Howto get count of unique users?
This is really dumb question but still my head cannot work it out. I have a table with Orders, each o开发者_JS百科rder has userID in it. User can have unlimited amount of Orders. How do i make count of unique userIDs ?
You can;
SELECT COUNT(DISTINCT userID)
FROM Tbl
You can give the count column a name by aliasing it:
SELECT COUNT(DISTINCT userID) NumberOfDistinctUsers
FROM Tbl
select count(*) from
(select distinct userid form ordertable) d
精彩评论