I denormalized my data (so a date is split up in a year, month, day and hour column)
But now I wonder how to query everything before a certain date.
This does NOT work:
SELECT *
FROM `impression_stat_hour`
WHERE doneforday =0
AND (
YEAR <=2011
AND MONTH <=6
AND DAY <=30
AND HOUR <=1
)
This won’t actually “group” all the records together as I want them too, resulting in date that is (for example) always from hour 0 and hour 1.
Or:
The latter is probably a lot slower (since it can’t use indexes on your various date columns. It’s also untested, since the only (ancient) version of MySQL I have access to doesn’t support STR_TO_DATE().