Hello folks. I'm new in this forum, but I have not found my question answered anywhere here so I guess it's OK for me to post it.
I have the following case.
Table [articleviews]
av_id
av_ip
av_datetime
This table records every presentation of any articles in my system.
The field [av_datetime] holds the date and time like yyyymmddhhmmss (14 chars)
What I would like to is to give in the current date/time (yyyymmddhhmmss) and retrieve the av_id (articleid) and two calculated fields. I want these calculated fields to be a counter for number of views for each [av_id] since (current datetime - 24 hours) and (current datetime - 24*7 hours).
example result:
.
..
...
av_id, av_countday, av_countweek
534, 45, 243
535, 34, 121
536, 56, 276
537, 12, 345
538, 19, 98
539, 23, 152
540, 31, 198
...
The av_countday and av_countweek should contain the count for each article for the last 24 hours and the last 24*7 hours.
I have solved this the easy way by using one record to hold the articles and the loop trough the postset and calculate (by SQL) for each of them. But I would like to do this by one single SQL-statement.
Any ideas ?
Thanx alot in advance.