SQL语句统计每天、每月、每年的数据

来源:互联网 发布:windows文件共享端口 编辑:程序博客网 时间:2024/05/22 03:51

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)

0 0
原创粉丝点击