您的位置:首页 > 数据库

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

2016-02-22 23:27 465 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: