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)
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)
相关文章推荐
- C#关于向数据库中插入数据时,有不规则自增列的处理方法
- 5. redis管道, 发布订阅, 模拟队列
- <MySQL管理之道第二版元旦截稿
- Sqlite中存储Boolean和boolean对象,分别使用boolean和text类型
- 数据库索引的实现原理
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio
- oracle登陆,在监听服务启动了的情况下,登陆用户还是报错未启动监听服务的错误(刚开始装oracle是能登陆的,重启之后装了plsql)
- oracle数据库dmp文件导入导出
- oracle之序列分析
- C#Winform Linq_to_Sql 实现增删改查功能
- 关于PostgreSQL编码
- 如何知道mysql中sql语句索引是否生效
- Android-节日短信送祝福(功能篇:1-数据库操作类与自定义ContentProvider)
- oracle之索引分析
- 数据库查询 所有表 以及 表的记录数
- 通用excel数据导出/转换(一)
- MySQL 数据库通过日志恢复
- mysql主从数据库不同步的2种解决方法(转)
- oracle体系结构-PGA
- MySQL 数据库-库与表的备份与还原