Hello, I have a mySQL database that has individual records for each time a page on my site is hit. What I'm trying to do is set up a tracking system which will display the hit counts for each page, by month, for the past three months, and ordered by total hits over that timespan.
The table is simple:
visitedPage | visitedTime
My current query is this:
SELECT visitedPage, count(*) AS Hits, month(visitedTime) AS Month, year(visitedTime) AS Year
FROM visited_pages
WHERE month(visitedTime) <6
AND month(visitedTime) >2
GROUP BY visitedPage, month(visitedTime), year(visitedTime)
ORDER BY visitedPage, Year ASC, Month ASC
which returns a resultset like this:
visitedPage | Hits | Month | Year
Background | 117 | 3 | 2006
Background | 121 | 4 | 2006
Background | 155 | 5 | 2006
Clients | 211 | 3 | 2006
Clients | 234 | 4 | 2006
Clients | 288 | 5 | 2006
etc.
the resultset I'd like to get is this:
visitedPage | totalHits | Hits | Month | Year
Background | 393 | 117 | 3 | 2006
Background | 393 | 121 | 4 | 2006
Background | 393 | 155 | 5 | 2006
Clients | 733 | 211 | 3 | 2006
Clients | 733 | 234 | 4 | 2006
Clients | 733 | 288 | 5 | 2006
etc.
I can't seem to get that all to happen with one query. Anyone have any suggestions?
Thanks.
The table is simple:
visitedPage | visitedTime
My current query is this:
SELECT visitedPage, count(*) AS Hits, month(visitedTime) AS Month, year(visitedTime) AS Year
FROM visited_pages
WHERE month(visitedTime) <6
AND month(visitedTime) >2
GROUP BY visitedPage, month(visitedTime), year(visitedTime)
ORDER BY visitedPage, Year ASC, Month ASC
which returns a resultset like this:
visitedPage | Hits | Month | Year
Background | 117 | 3 | 2006
Background | 121 | 4 | 2006
Background | 155 | 5 | 2006
Clients | 211 | 3 | 2006
Clients | 234 | 4 | 2006
Clients | 288 | 5 | 2006
etc.
the resultset I'd like to get is this:
visitedPage | totalHits | Hits | Month | Year
Background | 393 | 117 | 3 | 2006
Background | 393 | 121 | 4 | 2006
Background | 393 | 155 | 5 | 2006
Clients | 733 | 211 | 3 | 2006
Clients | 733 | 234 | 4 | 2006
Clients | 733 | 288 | 5 | 2006
etc.
I can't seem to get that all to happen with one query. Anyone have any suggestions?
Thanks.