我试图从上周获取我的查询结果。 数据库使用UNIX时间戳,因此只需几秒钟。
我已经想出了这个,但这似乎并不奏效。它给了我最好的结果。我只需要最后604.800秒的结果。
SELECT `mod_id`, COUNT(`mod_id`) m from `history_spottings` WHERE (`created` - 604800)
GROUP BY `mod_id`
ORDER BY m DESC;
答案 0 :(得分:1)
您的WHERE
条款有误,WHERE (created - 604800)
将始终评估为TRUE
,除非created
为空,它与WHERE 1
SELECT `mod_id`, COUNT(`mod_id`) m
from `history_spottings`
WHERE `created` >= UNIX_TIMESTAMP() - 604800
GROUP BY `mod_id`
ORDER BY m DESC;
答案 1 :(得分:0)
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;