sql 语句怎么写根据选择的年份统计出该年下每个月的订单总数

如题所述

这是一些统计每天、每月、每年的销售总额的查询语句,给你参考:
1、每年
select year(ordertime) 年,
sum(Total) 销售合计
from 订单表
group by year(ordertime)

2、每月
select year(ordertime) 年,
month(ordertime) 月,
sum(Total) 销售合计
from 订单表
group by year(ordertime),
month(ordertime

3、每日
select year(ordertime) 年,
month(ordertime) 月,
day(ordertime) 日,
sum(Total) 销售合计
from 订单表
group by year(ordertime),
month(ordertime),
day(ordertime)

另外每日也可以这样:
select convert(char(8),ordertime,112) dt,
sum(Total) 销售合计
from 订单表
group by convert(char(8),ordertime,112)

如果需要增加查询条件,在from后加where 即可。
温馨提示:答案为网友推荐,仅供参考
相似回答