统计时间段内周分类SQL语句
declare @datefrom as datetime,@dateto as datetime set @datefrom='2015-04-12'
set @dateto='2015-08-13' declare @table as table(dweek int,fdate datetime,tdate datetime)
declare @yearfrom as int,@monthfrom as int,@dayfrom as int
declare @yearto as int,@monthto as int,@dayto as int
set @yearfrom=year(@datefrom)
set @monthfrom=month(@datefrom)
set @dayfrom=day(@datefrom)
set @yearto=year(@dateto)
set @monthto=month(@dateto)
set @dayto=day(@dateto) declare @flag as int
set @flag=1 if(@flag=1)
begin
declare @firstDay as datetime, @currentDay as datetime,@monthdays as int
declare @curyear as int,@curmonth as int,@curday as int,@dweek as int,@firstflag int
set @curyear=@yearfrom
set @curmonth=@monthfrom
set @curday=@dayfrom set @firstflag=0
set @currentDay= str(@curyear) +'-'+str(@curmonth) +'-'+str(@curday)
set @dweek=1
while(@dateto>=@currentDay)
begin
set @firstDay= str(@curyear) +'-'+str(@curmonth) +'-01'
set @monthdays= day(dateadd(d,-day(@firstDay),dateadd(m,1,@firstDay)))
while(@monthdays>=@curday )
begin
set @currentDay= str(@curyear) +'-'+str(@curmonth) +'-'+str(@curday)
set @curday=@curday+1 if datepart(weekday,@currentDay)=1 and @dateto>=@currentDay
begin
if(@firstflag=1)
insert into @table(dweek,fdate,tdate)
select @dweek,dateadd(day,-6,@currentDay),@currentDay
else
insert into @table(dweek,fdate,tdate)
select @dweek,@datefrom,@currentDay set @dweek=@dweek+1
set @firstflag=1
end
end
set @curday=1
if(@curmonth=12)
begin
set @curmonth=1
set @curyear=@curyear+1
end
else
begin
set @curmonth=@curmonth+1
end
end
end if(datepart(weekday,@dateto)>1)
begin
insert into @table(dweek,fdate,tdate)
select @dweek,dateadd(day,2-datepart(weekday,@dateto),@dateto),@dateto
end select *from @table
统计时间段内周分类SQL语句的更多相关文章
- 使用mysqlbinlog从二进制日志文件中查询mysql执行过的sql语句 (原)
前提MySQL开启了binlog日志操作1. 查看MySQL是否开启binlog(进mysql操作) mysql> show variables like 'log_bin%'; 2 ...
- MySQL注入点与SQL语句的关系
目录 注入位置分类 内联式 - UNION query SQL injection 终止式 - End SQL injection 堆叠式 - Stacked queries SQL injectio ...
- sql server 查询性能最差的sql语句
SELECT TOP 10 TEXT AS 'SQL Statement' ,last_execution_time AS 'Last Execution Time' ,(total_logical_ ...
- mysql执行sql语句过程
开发人员基本都知道,我们的数据存在数据库中(目前最多的是mysql和oracle,由于作者更擅长mysql,所以这里默认数据库为mysql),服务器通过sql语句将查询数据的请求传入到mysql数据库 ...
- sql语句执行的时间
统计mysql里每条SQL语句执行的时间 收藏 CrazyHarry 发表于 2年前 阅读 3785 收藏 8 点赞 3 评论 3 Google.Github 双重认证前端课程,独家硅谷内容,每周直播 ...
- mysql按年度、季度、月度、周、日统计查询的sql语句
本文介绍一些mysql中用于查询的sql语句,包括按年度.季度.月度.周.日统计查询等,有需要的朋友,可以参考下. 一.年度查询 查询 本年度的数据 SELECT * FROM blog_arti ...
- 数据库:sql语句分别按日,按周,按月,按季统计金额
如: 表:consume_record 字段:consume (money类型) date (datetime类型) 请问怎么写四条sql语句分别按日,按周,按月,按季统计消费总量. 如:1月 120 ...
- vertica时间计算SQL语句实例:统计一天内登录的用户
SQL语句实例: select count(id) as num from public.user where cast((CURRENT_TIMESTAMP-login_timed) day as ...
- 数据库SQL语句查询指定时间段内的数据
[摘要]有的时候,我们需要查询数据库某段时间之间的数据,比如2016年5月1号到到5月3号之间用户注册数量(特殊节假日期间)等.那么用SQL语句如何实现呢? 首先,数据表中的存时间的字段比如是addt ...
随机推荐
- X-009 FriendlyARM tiny4412 uboot移植之SD Card用起来Kernel boot起来
<<<<<<<<<<<<<<<<<<<<<<<<< ...
- Python break 语句
Python break 语句 Python break语句,就像在C语言中,打破了最小封闭for或while循环. break语句用来终止循环语句,即循环条件没有False条件或者序列还没被完全递归 ...
- 如何将Emmet(ZenCoding)安装到到Dreamweaver8?
用过其他版本的Dreamweaver,还是习惯了Dreamweaver8,占用少,插件也容易安装,下面讲的是ZenCoding插件的安装方法,当然现在这个已经叫Emmet了. 安装方法: a.下载dw ...
- 如何使用Omnifocus做时间管理 4 多项目管理
这一篇和大家分享作为一个管理者,可能遇到的时间管理挑战和如何用omnifocus应对这些挑战. 张经理在一家IT公司上班,从程序员开始打拼了5年,凭借权威的技术能力当上了项目经理,同时管理三个项目,苦 ...
- Error: Cannot find module 'internal/fs'
$ sudo n 6.9.1 $ sudo npm -g install npm@next $ sudo n stable curl -0 -L https://npmjs.org/install.s ...
- 数学图形(2.13)Spherical trochoid曲线
该曲线与上一节的herical cycloid球面外摆曲线 很相似,难道这是球面内摆曲线? #http://www.mathcurve.com/courbes3d/cycloidspheric/tro ...
- 自建一个Java Spring MVC项目
用IDEA Intellij,本来创建的是SpringMVC项目,但是下载的时候,太慢了.所以还是用的Maven项目. 选择Maven 项目->Archetype->Web applica ...
- Django admin管理
admin的配置 admin是django强大功能之一,它能共从数据库中读取数据,呈现在页面中,进行管理.默认情况下,它的功能已经非常强大,如果你不需要复杂的功能,它已经够用,但是有时候,一些特殊的功 ...
- TensorFlow进阶(六)---模型保存与恢复、自定义命令行参数
模型保存与恢复.自定义命令行参数. 在我们训练或者测试过程中,总会遇到需要保存训练完成的模型,然后从中恢复继续我们的测试或者其它使用.模型的保存和恢复也是通过tf.train.Saver类去实现,它主 ...
- css整站规划
准备1 css reset /** * Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/) * http:/ ...