我有一个表,其中有一列称为时间戳记(YYYY-MM-DD HH:MM:SS
)和消息。我将如何显示每分钟发送的邮件数量(不只是在给定的时间内)。
我已经做到了,但是每次都可以。我将如何进行更改 计算从HH-00:00发送到HH:01:00的数量,以此类推。
SELECT timestamp, COUNT(*)
FROM Messages
GROUP BY timestamp
ORDER BY timestamp DESC
答案 0 :(得分:1)
尝试:
SELECT HOUR(timestamp) AS Hour,
MINUTE(timestamp) AS minute,
COUNT(*)
FROM Messages
GROUP BY HOUR(timestamp), MINUTE(timestamp)
ORDER BY HOUR(timestamp) DESC, MINUTE(timestamp) DESC
答案 1 :(得分:1)
SELECT TIMESTAMP(DATE(timestamp),MAKETIME(HOUR(timestamp),MINUTE(timestamp),0))
,COUNT(1)
FROM
Messages
GROUP BY TIMESTAMP(DATE(timestamp),MAKETIME(HOUR(timestamp),MINUTE(timestamp),0))
ORDER BY TIMESTAMP(DATE(timestamp),MAKETIME(HOUR(timestamp),MINUTE(timestamp),0))