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 即可。










相关文章:

  • 2021-10-17
  • 2021-10-30
  • 2022-12-23
  • 2021-07-01
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-10-13
  • 2022-12-23
相关资源
相似解决方案