统计时间段内周分类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 ...
随机推荐
- HTML5 Plus移动App(5+App)开发入门指南
HTML5 Plus移动App,简称5+App,是一种基于HTML.JS.CSS编写的运行于手机端的App,这种App可以通过扩展的JS API任意调用手机的原生能力,实现与原生App同样强大的功能和 ...
- Windows系统默认调试器设置
Windows系统默认调试器设置 1.使用运行打开drwtsn32 -i 注册华生医生到注册表如图: 2.使用运行打开drwtsn32可以进行一些常用的设置如图: 3. 注册表设置: HKEY_LOC ...
- java常用工具方法2
/* * Copyright 2005 Joe Walker * * Licensed under the Apache License, Version 2.0 (the "License ...
- Android学习笔记(三)之带有侧边索引的快速查找(跟带字母索引查找的通讯录差不多)
喜欢另辟蹊径的我,在这里废话不多说了,直接上代码和图片了. 效果图如下: 第一步:MainActivity的代码如下: package net.loonggg.test; import java.ut ...
- c#面试3(选择题)
1.下列有关基本类的大小不正确的是 A.int类型是4个字节 B.bool类型是1个字节 C.long类型是8个字节 D.char类型是一个字节 3.有关数组说法不正确的是 A.数组的内存是分配在栈中 ...
- Oracle初始安装内存设置参考
预备知识 shared memory:共享内存段: 一个内存区域,可以被不同的进程读取.oracle使用它来构成sga.oracle使用以下三种方法来创建一个sga区: 1. 使用单个共享内存段. ...
- pytest文档6-fixture之yield实现teardown
前言 上一篇讲到fixture通过scope参数控制setup级别,既然有setup作为用例之前前的操作,用例执行完之后那肯定也有teardown操作. 这里用到fixture的teardown操作并 ...
- Guava的使用
package guava; import java.io.File; import java.io.IOException; import java.util.ArrayList; import j ...
- TYVJ-P1864 守卫者的挑战 题解
P1864 [Poetize I]守卫者的挑战 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜 ...
- 对于Ian的访谈,不少关于GAN的内容
文章链接如下: http://3g.163.com/dy/article/DD1GBSLF0511ABV6.html 里面提到胶囊网络,我找了这篇文章看了下: https://blog.csdn.ne ...