2021-10-12 【技术解读】MYSQL查询每年每月每日总量 【技术解读】MYSQL查询每年每月每日总量 sql 语句解析date(create_date): 将日期格式化为 2000-01-01这种格式curdate() :获取当前日期 2020-06-30 等同于 date(now())date_sub(curdate(), interval 7 day): 获取7天前的日期统计每年的订单量SELECT YEAR(create_date) as year,COUNT(1) as count FROM orders GROUP BY year; 统计今年每个月的订单量SELECT MONTH(create_date) as month,COUNT(1) as count FROM orders WHERE YEAR(create_date) = YEAR(NOW()) GROUP BY month ORDER BY month; 统计今年每周的订单量SELECT WEEK(create_date) as week,COUNT(1) as count FROM orders WHERE YEAR(create_date) = YEAR(NOW()) GROUP BY week OR... 郑先森灬 2021-10-12 技术类 72 评论 2021年10月12日 0 阅读 72 评论