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;
参考:https://blog.csdn.net/u010946448/article/details/83752984
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341