SQL 查询--日期条件(今日、昨日、本周、本月。。。) (转)
主要用到sql 函数
DATEDIFF(datepart,startdate,enddate)

sql 语句,设 有 数据库表 tableA(日期字段ddate)
——查询 今日
select * from tableA where DateDiff(dd,VoucherDate,getdate())= 0
——查询 昨日
select * from tableA where DateDiff(dd,VoucherDate,getdate())= 1
——查询 本周
select * from tableA where DateDiff(dd,VoucherDate,getdate())<=7
——查询 上周
select * from tableA where DateDiff(dd,VoucherDate,getdate())>7 and DateDiff(dd,VoucherDate,getdate())<=14
——查询 本月
select * from tableA where DateDiff(mm,VoucherDate,getdate())= 0
——查询 上月
select * from tableA where DateDiff(mm,VoucherDate,getdate())= 1
——查询 本年
select * from tableA where DateDiff(yy,VoucherDate,getdate())= 0
——查询 上一年
select * from tableA where DateDiff(yy,VoucherDate,getdate())= 1
转载地址:https://www.cnblogs.com/carrot-z/p/9237915.html
SQL 查询--日期条件(今日、昨日、本周、本月。。。) (转)的更多相关文章
- SQL查询日期:
SQL查询日期: 今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0 昨天的所有数据:select * from ...
- sql 查询某个条件多条数据中最新的一条数据或最老的一条数据
sql 查询某个条件下多条数据中最新的一条数据或最老的一条数据 test_user表结构如下: 需求:查询李四.王五.李二创建的最初时间或者最新时间 1:查询最初的创建时间: SELECT * FRO ...
- SQL 查询当天,本月,本周的记录 sql 查询日期
SELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GETDATE(), 111) ORDE ...
- 使用Sql按日期条件查询
--查询当天(1: select * from ShopOrder where datediff(day,ordTime,getdate()-1)=0 --查询当天(2:select * from i ...
- ADO SQL delete 日期条件参数
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- SQL查询符合条件的记录的总数
1. select count(*) from table; //统计元组个数 2. select count(列名) from table; //统计一列中值的个数 3. select co ...
- SQL查询日期格式化
MARK一下 方便以后自己查阅 举例如下: getdate() 可以替换成日期类型字段 select Convert(varchar(10),getdate(),120) 2006-05-12sele ...
- vue项目中使用日期获取今日,昨日,上周,下周,上个月,下个月的数据
今日公司项目接口要求获取动态的上周数据,经过不断的寻找,找到此方法. 该方法使用的是Moment.js JavaScript日期处理类库 一:安装依赖 npm install moment --sav ...
- Sql Server中查询今天、昨天、本周、上周、本月、上月数据
Sql Server中查询今天.昨天.本周.上周.本月.上月数据 在做Sql Server开发的时候有时需要获取表中今天.昨天.本周.上周.本月.上月等数据,这时候就需要使用DATEDIFF()函数及 ...
随机推荐
- UVA-699-The Falling Leaves-二叉树+递归
Each year, fall in the North Central region is accompanied by the brilliant colors of the leaves on ...
- visual studio 注释模板
/*----------------------------------------------------------------* 项目名称 :$rootnamespace$* 项目描述 :* 类 ...
- iOS开发系列-Block本质篇
概述 在iOS开发中Block使用比较广泛,对于使用以及一些常规的技术点这里不再赘述,主要利用C++角度分析Block内部数据底层实现,解开开发中为什么这样编写代码解决问题. Block底层结构窥探 ...
- linux的mysql权限错误导致看不到mysql数据库
1.首先停止mysql服务:service mysqld stop2.加参数启动mysql:/usr/bin/mysqld_safe --skip-grant-tables & 然后就可以无任 ...
- openSUSE 安装compass,mkmf.rb can't find,checking for ffi.h...extconf.rb failed
安装compass时,提示 Fetching: sass-.gem (%) Successfully installed sass- Fetching: ffi-.gem (%) Building n ...
- TokuDB安装
安装TokuDB 1, 创建mysql数据目录 #顺便把临时目录创建好 mkdir -p /data/mysql/tmp groupadd -r mysql useradd -g mysql -r - ...
- htaccess apache重定向学习
1.推荐博客:http://www.cnblogs.com/adforce/archive/2012/11/23/2784664.html 2.测试工具:https://htaccess.madewi ...
- linux 软件 手动添加至桌面或启动栏
1.创建软连接(也可以不用创建软连接,直接写绝对路径) sudo ln -s /opt/eclipse/eclipse /usr/bin/eclipse 2.创建desktop文件 sudo gedi ...
- nginx 解决问题
- Docker系列(十一):Kubernetes集群集群部署实践
Kubernetes分布式集群架构 服务注册和服务发现问题怎么解决的? 分布式通讯的核心就是ip加端口 每个服务分配一个不变的虚拟IP+端口 系统env环境变量里有每个服务的服务名称到IP的映射 如下 ...