Hi
I have a database table full of events and dates and I'm trying to find the last occurrence and age of each event. (Age is obviously the time elapsed since the last occurrence)
So, I have the following query:
Quote:
SELECT max(date) as last,
min(curdate()-date) AS age
FROM event_data
WHERE event = $event
GROUP BY event" |
(This Query returns one row of data within a WHILE loop for every event. I think the "GROUP BY" is unnecessary)
A partial list of the results are as follows:
Event - Count - Last - Age
56 - 15 - 2012-10-27 - 191
59 - 13 - 2012-11-17 - 101
44 - 13 - 2012-12-15 - 3
29 - 13 - 2012-11-28 - 90
7 - 12 - 2012-12-08 - 10
5 - 12 - 2012-11-28 - 90
(the "Count" field is the number of occurrences coming from another query)
Today's date is 2012-12-18. For some reason, all of the December ages are correct but the older ones are WAY off.
What have I done wrong?