请假以时间间隔为周期求和的sql语句
时间:2011-12-13
来源:互联网
原始表格式
theDate nums
----------------- ----------
2011-12-02 3
2011-12-03 3
2011-12-04 1
.....................
.....................
.....................
2011-12-06 3
2011-12-07 1
2011-12-08 2
--------------------------------
结果格式
年份 周数 汇总
2011 1 111
2011 2 123
2011 3 56
2011 4 78
.....................
.....................
.....................
2011 25 95
作者: marklr 发布时间: 2011-12-13

作者: bancxc 发布时间: 2011-12-13
select datepart(yy,theDate) as 年份, datepart(week,theDate) as 周数, sum(nums) as 汇总 from tb group by datepart(yy,theDate), datepart(week,theDate)
作者: fredrickhu 发布时间: 2011-12-13
select year(theDate)年份,datepart(wk,theDate)周数,sum(nums)汇总 from tb group by year(theDate),datepart(wk,theDate)
作者: qianjin036a 发布时间: 2011-12-13
create table aaa(thedate datetime,nums int) insert into aaa select '2011-12-02', 3 union all select '2011-12-03' ,3 union all select '2011-12-04', 1 union all select '2011-12-06', 3 union all select '2011-12-07', 1 union all select '2011-12-08', 2 select year(thedate) 年份,datepart(wk,thedate) 周数,sum(nums) 汇总 from aaa group by year(thedate),datepart(wk,thedate) /* 2011 49 6 2011 50 7 */
作者: sjcss 发布时间: 2011-12-13
select datepart(week ,[theDate]),count(1) from [ta] group by datepart(week ,[theDate])
作者: Beirut 发布时间: 2011-12-13
select year(thedate) as 年份,datepart(wk,thedate) as 周数,sum(nums) as 汇总 from [ta] group by year(thedate),datepart(wk,thedate)
作者: Beirut 发布时间: 2011-12-13
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28