统计销售额

一、每一年
select year(ordertime) 年,
sum(Total) 销售合计
from
订单表
group by year(ordertime)
二、每个月
select year(ordertime) 年,
month(ordertime) 月,
sum(Total) 销售合计
from
订单表
group by year(ordertime),
month(ordertime
三、每日
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 便可。
相关文章
相关标签/搜索