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)
 GROUP BY

Author  Topic 

nietzky
Yak Posting Veteran

75 Posts

Posted - 2013-10-17 : 15:05:59
I have a table that looks like this:
SID Pages PageViews Visits CheckDate
Peter http://X1.somehostname.net/page1.aspx 4 3 9/2/2013
Peter http://X1.somehostname.net/page2.aspx 1 1 9/2/2013
George http://X1.somehostname.net/page3.aspx 4 4 9/2/2013
George http://X1.somehostname.net/secure/page4.aspx 3 3 9/2/2013
George http://X1.somehostname.net/secure/page5.aspx 2 1 9/2/2013
George http://X1.somehostname.net/page6.aspx 3 3 9/2/2013
George http://X1.somehostname.net/page7.aspx 4 4 9/2/2013
George http://X1.somehostname.net/page8.aspx 1 1 9/2/2013
Albert http://X1.somehostname.net/page1.aspx 1 1 9/2/2013
Albert http://X1.somehostname.net/page3.aspx 0 1 9/2/2013
Albert http://X1.somehostname.net/page21.aspx 1 1 9/2/2013
Albert http://X1.somehostname.net/page17.aspx 1 1 9/2/2013
Peter http://X1.somehostname.net/page1.aspx 4 3 9/9/2013
Peter http://X1.somehostname.net/page2.aspx 1 1 9/9/2013
George http://X1.somehostname.net/page3.aspx 15 15 9/16/2013
George http://X1.somehostname.net/secure/page4.aspx 102 17 9/16/2013
George http://X1.somehostname.net/secure/page5.aspx 0 1 9/16/2013
George http://X1.somehostname.net/page6.aspx 2 1 9/16/2013
George http://X1.somehostname.net/page7.aspx 2 1 9/16/2013
George http://X1.somehostname.net/page8.aspx 1 1 9/16/2013


I would like to show how many unique visits per date do I have. Date is weekly. In other words I would like to count unique SIDs per date.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-17 : 15:16:00
[code]SELECT
CheckDate,
COUNT(DISTINCT SID) AS UniqueVisits
FROM
YourTable
GROUP BY
CheckDate;[/code]
Go to Top of Page

nietzky
Yak Posting Veteran

75 Posts

Posted - 2013-10-18 : 13:40:22
Thank you
Go to Top of Page
   

- Advertisement -