我需要一个查询,它会在过去48小时内每小时返回一次计数。 到现在为止我试过了:
SELECT count(*), date_format(created, '%H:%i - %d/%m/%y') as datecreated
FROM mimesi_indexer.served_clips
where created > NOW() - INTERVAL 24 HOUR
group by floor(hour(created))
order by created ASC
和
SELECT count(*), date_format(created, '%H:%i - %d/%m/%y') as datecreated
FROM mimesi_indexer.served_clips
where created > NOW() - INTERVAL 48 HOUR
group by floor(hour(created))
order by created ASC
但这些都没有给出想要的结果。 你对我怎么做这个有什么想法吗? 感谢
答案 0 :(得分:2)
如果你想要每个小时,不要这样:
SELECT count(*), date_format(created, '%H - %d/%m/%y') as datecreated
FROM mimesi_indexer.served_clips
where created > NOW() - INTERVAL 24 HOUR
group by date_format(created, '%H - %d/%m/%y')
order by min(created) ASC;
也就是说,您需要包含日期和小时 - 并从datecreated
中删除分钟。