# 查询每天的数据
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') AS dateTime,
addtime
FROM admin_log
GROUP BY DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') ;
本月每天 DATE_FORMAT(时间字段,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m');
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') AS dateTime,
addtime
FROM admin_log
WHERE DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y%m')= DATE_FORMAT(CURDATE(),'%Y%m')
GROUP BY DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') ;
# 查询每月的数据:by month
SELECT
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m') AS month,
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-01') AS createDate,
COUNT(*) AS countNumber
FROM project_case
GROUP BY month ORDER BY month ASC;
# 查询每年的数据
SELECT
COUNT(1) AS countNumber,
YEAR(DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d')) AS dateTime
FROM admin_log
GROUP BY YEAR(DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d')) ;
时间为日期类型==================================================
# 查询每天的数据
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(create_time,'%Y-%m-%d') AS dateTime
FROM project_case
GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d');
# 查询每周的数据
SELECT
DATE_FORMAT(create_time,'%Y-%u') AS week,
DATE_FORMAT(DATE_SUB(create_time,INTERVAL DAYOFWEEK(create_time) - 2 DAY),'%Y-%m-%d') AS createDate,
COUNT(*) AS countNumber
FROM project_case
GROUP BY week ORDER BY week ASC;
# 查询每月的数据:by month
SELECT
DATE_FORMAT(create_time,'%Y-%m') AS month,
DATE_FORMAT(create_time,'%Y-%m-01') AS createDate,
COUNT(*) AS countNumber
FROM project_case
GROUP BY month ORDER BY month ASC;
# 查询每年的数据
SELECT
COUNT(1) AS countNumber,
YEAR(create_time) AS dateTime
FROM project_case
GROUP BY dateTime;
参考:https://www.jianshu.com/p/3f25da4c9a07
https://blog.csdn.net/VIP_1205169154/article/details/108552768
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') AS dateTime,
addtime
FROM admin_log
GROUP BY DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') ;
本月每天 DATE_FORMAT(时间字段,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m');
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') AS dateTime,
addtime
FROM admin_log
WHERE DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y%m')= DATE_FORMAT(CURDATE(),'%Y%m')
GROUP BY DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d') ;
# 查询每月的数据:by month
SELECT
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m') AS month,
DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-01') AS createDate,
COUNT(*) AS countNumber
FROM project_case
GROUP BY month ORDER BY month ASC;
# 查询每年的数据
SELECT
COUNT(1) AS countNumber,
YEAR(DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d')) AS dateTime
FROM admin_log
GROUP BY YEAR(DATE_FORMAT(FROM_UNIXTIME(addtime),'%Y-%m-%d')) ;
时间为日期类型==================================================
# 查询每天的数据
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(create_time,'%Y-%m-%d') AS dateTime
FROM project_case
GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d');
# 查询每周的数据
SELECT
DATE_FORMAT(create_time,'%Y-%u') AS week,
DATE_FORMAT(DATE_SUB(create_time,INTERVAL DAYOFWEEK(create_time) - 2 DAY),'%Y-%m-%d') AS createDate,
COUNT(*) AS countNumber
FROM project_case
GROUP BY week ORDER BY week ASC;
# 查询每月的数据:by month
SELECT
DATE_FORMAT(create_time,'%Y-%m') AS month,
DATE_FORMAT(create_time,'%Y-%m-01') AS createDate,
COUNT(*) AS countNumber
FROM project_case
GROUP BY month ORDER BY month ASC;
# 查询每年的数据
SELECT
COUNT(1) AS countNumber,
YEAR(create_time) AS dateTime
FROM project_case
GROUP BY dateTime;
参考:https://www.jianshu.com/p/3f25da4c9a07
https://blog.csdn.net/VIP_1205169154/article/details/108552768
继续阅读与本文标签相同的文章
上一篇 :
MySQL以逗号隔开的字符串查询方式整理
下一篇 :
PHP无限分类或者无限评论数组分页方法
-
阿里云Linux服务器动态扩容(阿里云服务器扩容后磁盘空间无变化解决方法)
2020-11-30栏目: 建站教程
-
6个SEM实战技巧,大神手把手教你做推广!
2020-07-20栏目: SEM
-
苏州美食推荐,持续更新
2020-06-17栏目: 生活笔记
-
企业如何玩转视频号
2020-05-12栏目: 运营杂谈
-
SEO关键词排名该掌握的核心优化技巧
2020-05-12栏目: SEO
打印
分享
发表评论 已发布 0 条