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 2005 Forums
 Transact-SQL (2005)
 sql count

Author  Topic 

jameswoodmancy
Starting Member

13 Posts

Posted - 2009-07-08 : 11:48:50
Hi, I want to perform a sql statement which counts the number of times a page has been visisted..like this

SELECT Title FROM Page ,(SELECT COUNT(*) FROM UserJourney WHERE Page.ID = UserJourney.PageID) AS ViewCount
FROM [Pages]
ORDER BY [OrderBy]

however, i have a column called sessionID in the table UserJourney and I want to group by this column so if a user goes to the page twice in one session then it will only be counted once. I'm having difficulty working out the SQL statement for this. any ideas where to start?

thanks for your help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 11:58:49
[code]
SELECT p.Title, uj.ViewCount
FROM [Pages] p
CROSS APPLY (SELECT COUNT(DISTINCT sessionID) AS ViewCount FROM UserJourney WHERE PageID=p.ID ) uj
ORDER BY [OrderBy]
[/code]
Go to Top of Page

jameswoodmancy
Starting Member

13 Posts

Posted - 2009-07-13 : 12:05:46
thanks!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-13 : 13:46:41
welcome
Go to Top of Page
   

- Advertisement -