EYblog - Powered by Eyblog - 统计
type: channel
link: https://www.jwwey.com/index.php/tag/统计/
items: 【技术解读】MYSQL查询每年每月每日总量

【技术解读】MYSQL查询每年每月每日总量
type: item
date: 2021-10-12T14:42:00+08:00
description: 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 ORDER BY week; 统计今年每日的订单量select DATE_FORMAT(createtime,'%Y-%m-%d') as days,count(*) count from ibt_shop_order group by days;