每分钟的插入量sql

pu82cl6c  于 2021-06-19  发布在  Mysql
关注(0)|答案(2)|浏览(385)

我有一个表,表中有一列叫做timestamp( YYYY-MM-DD HH:MM:SS )和信息。我将如何显示每分钟(而不仅仅是在给定的时间)发送多少条消息。
我做过但每次都是这样。我将如何改变它来计算从hh-00:00发送到hh:01:00的号码,以此类推。

SELECT timestamp, COUNT(*)
FROM Messages
GROUP BY timestamp
ORDER BY timestamp DESC
xj3cbfub

xj3cbfub1#

尝试:

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
cczfrluj

cczfrluj2#

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))

相关问题