大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说mysql统计,希望您对编程的造诣更进一步.
-- 时间转任意格式DATE_FORMAT
-- #select DATE_FORMAT(NOW(),"%m-%d-%Y");
-- unix_timestamp 时间转时间戳
-- select unix_timestamp(now());
-- from_unixtime 时间戳转时间
-- SELECT from_unixtime(created_time,"%m-%d-%Y")
#按天统计
-- SELECT from_unixtime(created_time,"%m-%d-%Y") AS date, COUNT(*) AS num
-- FROM filter_ip
-- GROUP BY date
-- ORDER BY date;
#按小时统计
-- SELECT from_unixtime(created_time, "%Y-%m-%d %H:00:00") AS time, COUNT(*) AS num
-- FROM filter_ip
-- GROUP BY time
-- ORDER BY time;
#按分钟统计
-- SELECT DATE_FORMAT(from_unixtime(created_time), "%Y-%m-%d %H:%i:00") AS time, COUNT(*) AS num
-- FROM filter_ip
-- GROUP BY time
-- ORDER BY time;
#按十分钟统计、按半小时统计只需要把10改为30
SELECT time, COUNT( * ) AS num
FROM
(
SELECT
DATE_FORMAT(
concat( date( from_unixtime(created_time) ), " ", HOUR ( from_unixtime(created_time) ), ":", floor( MINUTE ( from_unixtime(created_time) ) / 10 ) * 10 ),
"%Y-%m-%d %H:%i"
) AS time
FROM filter_ip
) a
GROUP BY DATE_FORMAT( time, "%Y-%m-%d %H:%i" )
ORDER BY time;
代码100分
参考:https://blog.csdn.net/u010946448/article/details/83752984
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/8781.html