I posted this before, but got no response. It is really driving me crazy! It seems whenever I do a sum one of the rows that should be added is not getting added.
I am attempting to write a simple stats program for different pages on my site. Each page has a pageID, and the stats are stored in a table called 'stats'. I am getting wacky results. The primary key is a timestamp called 'logTimeStamp'.
I am trying to see how many hits a page gets based on the hour of the day:
Here's a sample of some data:
pageID | logTimeStamp | hits
---------------------------------------
252 | 20001116142026 | 52
---------------------------------------
252 | 20001116142928 | 1
---------------------------------------
252 | 20001115142428 | 1
---------------------------------------
252 | 20001115194450 | 1
---------------------------------------
Here's the query:
"SELECT HOUR(logTimeStamp), SUM(hits) FROM stats WHERE pageID = 252 GROUP BY(HOUR(logTimeStamp)) ORDER BY logTimeStamp"
Here's the result:
HOUR(logTimeStamp) | SUM(hits)
------------------------------------
19 | 0
------------------------------------
14 | 53
So what is going wrong? Clearly the sum for the HOUR 19 should be 1 and the sum for HOUR 14 should be 54.
I know others have had this problem, but no answers seemed to help.
Thanks
I am attempting to write a simple stats program for different pages on my site. Each page has a pageID, and the stats are stored in a table called 'stats'. I am getting wacky results. The primary key is a timestamp called 'logTimeStamp'.
I am trying to see how many hits a page gets based on the hour of the day:
Here's a sample of some data:
pageID | logTimeStamp | hits
---------------------------------------
252 | 20001116142026 | 52
---------------------------------------
252 | 20001116142928 | 1
---------------------------------------
252 | 20001115142428 | 1
---------------------------------------
252 | 20001115194450 | 1
---------------------------------------
Here's the query:
"SELECT HOUR(logTimeStamp), SUM(hits) FROM stats WHERE pageID = 252 GROUP BY(HOUR(logTimeStamp)) ORDER BY logTimeStamp"
Here's the result:
HOUR(logTimeStamp) | SUM(hits)
------------------------------------
19 | 0
------------------------------------
14 | 53
So what is going wrong? Clearly the sum for the HOUR 19 should be 1 and the sum for HOUR 14 should be 54.
I know others have had this problem, but no answers seemed to help.
Thanks