MySQL中统计一天之内每个时间段内的数据,很急

MySQL中统计一天之内每个时间段内的数据,很急,第1张

时间段统计,可以采用 hour(subscribe_time) 取出小时然后分层。思路:

select

uid

,CASE WHEN HOUR(subscribe_time) BETWEEN 0 AND 1 THEN '00:00:00'

WHEN HOUR(subscribe_time) BETWEEN 2 AND 3 THEN '02:00:00'

...

ELSE '23:00:00' END -- 生成时间分层部分,insert前外层sql加上日期后作为唯一的时间值

,COUNT(*)

FROM yht_fans WHERE subscribe_time>=UNIX_TIMESTAMP(CURDATE()) and subscribe_time<=UNIX_TIMESTAMP(CURDATE())+86400

GROUP BY 1,2

SELECT * FROM NODE

WHERE PREV_NODE_ID NOT IN (SELECT DISTINCT NODE_ID FROM NODE)

AND PRNT_NODE_ID NOT IN (SELECT DISTINCT NODE_ID FROM NODE)

将 SELECT * 换成 DELETE 即可删除了

那就将语句改成下面这样

DELETE FROM NODE A

WHERE A.PREV_NODE_ID NOT IN (SELECT DISTINCT B.NODE_ID FROM NODE B WHERE B.ID = A.ID)

AND A.PRNT_NODE_ID NOT IN (SELECT DISTINCT B.NODE_ID FROM NODE B WHERE B.ID = A.ID)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8708062.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-20
下一篇 2023-04-20

发表评论

登录后才能评论

评论列表(0条)

保存