SQL语句统计天天、每个月、每一年的数据
时间 2019-12-06
标签
sql
语句
统计
天天
每个月
每一年
数据
SQL语句统计天天、每个月、每一年的数据
spa
一、每一年 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)ci |