- 1、每年
- select year(ordertime) AS '年',
- sum(Total) '销售合计'
- from order_list
- group by year(ordertime)
- 2、每月
- select year(ordertime) '年',
- month(ordertime) '月',
- sum(Total) '销售合计'
- from order_list
- group by year(ordertime),
- month(ordertime)
- 3、每日
- select year(ordertime) '年',
- month(ordertime) '月',
- day(ordertime) '日',
- sum(Total) '销售合计'
- from order_list
- group by year(ordertime),
- month(ordertime),
- day(ordertime)
- 另外每日也可以这样:
- select convert(char(8),ordertime,112) dt,
- sum(Total) '销售合计'
- from order_list
- group by convert(char(8),ordertime,112)
- 另外,每月(年、日)的记录条数
- select year(ordertime) '年',
- month(ordertime) '月',
- count(*) '销售记录'
- from order_list
- group by year(ordertime),
- month(ordertime)
SQL语句统计每天、每月、每年的 数据
最新推荐文章于 2024-04-10 09:42:18 发布