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

本文介绍如何根据订单表中的日期字段(ordertime),按年、月、日进行销售数据汇总,包括按年汇总、按月汇总和按日汇总的方法。
2218

被折叠的 条评论
为什么被折叠?



