Laurenz Laeremans Laurenz Laeremans - 2 years ago 115
SQL Question

Mysql query results from last 604800 seconds

I'm trying to get my query results from last week.
The database uses UNIX Timestamp, so it's in seconds.

I've come up with this, but that doesn't seem to work. It gives me the all-time results. I just needs the results from the last 604.800 seconds.

SELECT `mod_id`, COUNT(`mod_id`) m from `history_spottings` WHERE (`created` - 604800)
GROUP BY `mod_id`
ORDER BY m DESC;

Answer Source
SELECT `mod_id`, COUNT(`mod_id`) m from `history_spottings` WHERE `created` BETWEEN (UNIX_TIMESTAMP() - 604800) AND (UNIX_TIMESTAMP())
GROUP BY `mod_id`
ORDER BY m DESC;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download