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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query Help: Total UNIQUE Users Per Version

Author  Topic 

BaggaDonuts
Yak Posting Veteran

52 Posts

Posted - 2011-03-10 : 00:14:51
Say I have a table:

UserActivity
UserId int
Version int
ActivityDate smalldatetime
SomeData varchar(max)


This table has no constraints

I want to get the total UNIQUE users per version. i tried the following query:

select Version, count(UserId)
from UserActivity
group by Version

but that gives me the total number of users per version not the total number of unique users. can someone help me out?

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-10 : 00:31:10
Use this

select Version, count(Distinct UserId)
from UserActivity
group by Version

Cheers
MIK
Go to Top of Page

BaggaDonuts
Yak Posting Veteran

52 Posts

Posted - 2011-03-10 : 01:41:50
Nice that worked. thanks
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-10 : 01:50:31
WElcome

Cheers
MIK
Go to Top of Page
   

- Advertisement -