SQLserver 按日、周、月统计数据
来源:互联网 发布:mac版国服lol 编辑:程序博客网 时间:2024/06/06 03:00
create table T(日期时间 datetime, 数量 int)
insert T select '2007-1-1 19:31:25 ', 56
union all select '2007-1-1 21:31:25 ', 35
union all select '2007-1-1 15:31:25 ', 43
union all select '2007-1-2 19:31:25 ', 34
union all select '2007-1-3 15:31:25 ', 35
union all select '2007-1-3 21:31:25 ', 65
--按日统计
select 日期时间=convert(char(10), 日期时间, 120), 数量=sum(数量)
from T
group by convert(char(10), 日期时间, 120)
--按周统计
select 日期时间=datepart(week, 日期时间), 数量=sum(数量)
from T
where year(日期时间)=year(getdate())
group by datepart(week, 日期时间)
--按月统计
select 日期时间=convert(char(7), 日期时间, 120), 数量=sum(数量)
from T
group by convert(char(7), 日期时间, 120)
实例:
按日统计
select sum(cniTicketCount) as STickCount,Convert(varchar(10),cnAppDate,23) as ScnAppDate from
(select B.*,U.UserName from SystemUsers U inner join BookingDetails B on U.AutoID=B.cnvcApplyMan
where B.cniTicketCount>0 and B.cnAppDate between '2010/09/01' and '2010/10/01') as A
group by Convert(varchar(10),cnAppDate,23)
按周统计
select sum(cniTicketCount) as STickCount,datepart(week,cnAppDate)as ScnAppDate from
(select B.*,U.UserName from SystemUsers U inner join BookingDetails B on U.AutoID=B.cnvcApplyMan
Where B.cniTicketCount>0) as A
group by datepart(week,cnAppDate)
按月统计
select sum(cniTicketCount) as STickCount,substring(Convert(varchar(10),cnAppDate,23),1,7) as ScnAppDate from
(select B.*,U.UserName from SystemUsers U inner join BookingDetails B on U.AutoID=B.cnvcApplyMan
Where B.cniTicketCount>0) as A
group by substring(Convert(varchar(10),cnAppDate,23),1,7)
- SQLserver 按日、周、月统计数据
- MySQL 按日、周、月分组统计数据
- MySql按日/周/月分组统计数据
- sqlserver 按日、周、月统计方法
- SQLServer 按日,周,月,季,年统计
- MySql之按周,按月,按日分组统计数据
- Oracle按日期分组统计数据
- Sql按日周月数据查询
- mysql按日、月、周、季度分组
- SQL按日、周、月、年统计
- oracle sql 按日,周,月,年统计
- Mysql按日、周、月进行分组统计
- SQL按照日、周、月、年统计数据
- SQL按照日、周、月、年统计数据
- SQL按照日、周、月、年统计数据
- mysql 按照天 周 月 年 统计数据
- SQL按照日、周、月、年统计数据
- SQL按照日、周、月、年统计数据
- Silverlight与WPF中BeginInvoke的差异
- c++中构造函数初始化的方法以及主要区别
- 对AlertDialog的总结
- iOS AQPlayer 设置扬声器播放
- DBA面试题
- SQLserver 按日、周、月统计数据
- hbase常见错误
- SAP ABAP 选择画面 年/月的F4帮助
- 改变AlertDialog 的大小
- A*路径寻找算法入门
- 深入Java集合学习系列:HashMap的实现原理
- MySQL常用命令
- Android 中的 Looper 对象
- 嵌入式设备上的LINUX系统开发与嵌入式linux的入门学习介绍