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()函数及 ...
随机推荐
- PHP面向对象之继承的基本思想
图例 概念和说明 代码展示 <?php header('content-type:text/html;charset=utf-8'); //学生考试系统 class Student{ publi ...
- Spring - 整合MyBatis
目的: 使用 Spring 容器用单例模式管理 MyBatis 的 sqlSessionFactory : 使用 Spring 管理连接池.数据源等: 将 Dao / Mapper 动态代理对象注入到 ...
- FineUI使用记录
@{ ViewBag.Title = "Grid/Grid"; var F = Html.F();} @section body { @(F.Grid().IsFluid(true ...
- [WPF自定义控件]?使用WindowChrome自定义Window Style
原文:[WPF自定义控件]?使用WindowChrome自定义Window Style 1. 为什么要自定义Window 对稍微有点规模的桌面软件来说自定义的Window几乎是标配了,一来设计师总是克 ...
- vue_cli 安装
1.安装node 2.cmd node-v3.如果是刚刚安装输入 node-v 会成功出现版本 如果不是全局安装 过段时间输入 node-v会出现 'node' 不是内部或外部命令,也不是可运行的程序 ...
- [记录]学习树莓派3B接DHT11和LCD1602和修改树莓派时区
前提 树莓派系统安装好 apache web 服务器,如未安装,可在树莓派内执行sudo apt-get install apache2 进行安装apache 也可以通过命令获取GPIO信息: gpi ...
- linux 服务 启动 关闭 列表
##查看服务在每个级别的运行状态 chkconfig --list httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:启用 6:关闭 bluetooth ...
- python csv write 乱码
参考 : https://www.zhihu.com/question/34201726 1.使用utf_8_sig with open('d:/file.csv', 'w', encoding='u ...
- leetcode-122-买卖股票的最佳时机②
题目描述: 方法一: class Solution: def maxProfit(self, prices: List[int]) -> int: profit = 0 for i in ran ...
- day3-编码、文件、集合、函数、递归
学习内容: 1. 文件编码 2. 文件 3. 集合 4.函数 5.递归 6.匿名函数 1. 文件编码: 常见的字符串编码有:ASCII 扩展的ASCII Unicode GBK GB2312 GB18 ...