sql查询一天内的where写法,sql写法
sql查询一天内的写法:
1.
where createtime
BETWEEN (select date_format(now(),'%Y-%m-%d 00:00:00'))
and (select date_format(now(),'%Y-%m-%d 23:59:59'))
2.
SELECT TO_DAYS(now());
SELECT TO_DAYS('2016-07-02 20:50:06');
========================================附录============================================
今天 select * from 表名 where to_days(时间字段名) = to_days(now());
昨天Select * FROM 表名 Where TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <=
7天Select * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL DAY) <= date(时间字段名)
近30天Select * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL DAY) <= date(时间字段名)
本月Select * FROM 表名 Where DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
上一月Select * FROM 表名 Where PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( 时间字段名, '%Y%m' ) ) =
#查询本季度数据
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now());
#查询上季度数据
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval QUARTER));
#查询本年数据
select * from `ht_invoice_information` where YEAR(create_date)=YEAR(NOW());
#查询上年数据
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval year)); 查询当前这周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());
查询上周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-;
查询当前月份的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')
查询距离当前现在6个月的数据
select name,submittime from enterprise where submittime between date_sub(now(),interval month) and now();
查询上个月的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL MONTH),'%Y-%m')
select * from ` user ` where DATE_FORMAT(pudate, ' %Y%m ' ) = DATE_FORMAT(CURDATE(), ' %Y%m ' ) ;
select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d')) = WEEKOFYEAR(now())
select *
from user
where MONTH (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = MONTH (now())
select *
from [ user ]
where YEAR (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = YEAR (now())
and MONTH (FROM_UNIXTIME(pudate, ' %y-%m-%d ' )) = MONTH (now())
select *
from [ user ]
where pudate between 上月最后一天
and 下月第一天
where date(regdate) = curdate();
select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())
SELECT date( c_instime ) ,curdate( )
FROM `t_score`
WHERE
LIMIT ,
sql查询一天内的where写法,sql写法的更多相关文章
- SQL反模式学习笔记18 减少SQL查询数据,避免使用一条SQL语句解决复杂问题
目标:减少SQL查询数据,避免使用一条SQL语句解决复杂问题 反模式:视图使用一步操作,单个SQL语句解决复杂问题 使用一个查询来获得所有结果的最常见后果就是产生了一个笛卡尔积.导致查询性能降低. 如 ...
- sql查询指定范围内的所有月份
),) FROM master..spt_values WHERE type='P' AND DATEADD(MONTH,number,'2016-01-01')<='2017-01-01'
- SQL查询一周内过生日的用户
SELECT birthday, )) + '-' + )) + '-' + )) AS datetime) AS Nbirthday FROM CRM_Customer WHERE birthday ...
- SQL 查询同一天日期内的数据
条件如下: convert(date,a.dtClock) = convert(date,b.dtClock)
- sql---如何把sql查询出来的结果当做另一个sql的条件查询,1、语句2、with as
'; -- table2 的 name 作为 table1的条件 select * from table1 where name in (select name from table2) --如果有多 ...
- mysql体系结构和sql查询执行过程简析
一: mysql体系结构 1)Connectors 不同语言与 SQL 的交互 2)Management Serveices & Utilities 系统管理和控制工具 备份和恢复的安全性,复 ...
- 不得不看,只有专家才知道的17个SQL查询提速秘诀!
不得不看,只有专家才知道的17个SQL查询提速秘诀! 原创 2018-01-23 布加迪编译 51CTO技术栈 “ 除非你遵循本文介绍的这些技巧,否则很容易编写出减慢查询速度或锁死数据库的数据库代码. ...
- 【T-SQL基础】01.单表查询-几道sql查询题
概述: 本系列[T-SQL基础]主要是针对T-SQL基础的总结. [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础]02.联接查询 [T-SQL基础]03.子查询 [T-SQL基础 ...
- JavaEE(18) - JPA原生SQL查询和存储过程
1. 使用原生SQL执行查询 2. 映射原生SQL查询的结果集 3. 使用原生SQL查询执行实体查询 4. 命名原生SQL查询 5. 在JPQL查询中调用存储过程
随机推荐
- MyEclipse常用插件使用教程
一.Findbugs 1. 配置 1.1 打开FindBugs视图: Windows => Show View => Other… => FindBugs => Bug Inf ...
- 在Java中如何实现“Pless presss any key to continue.”
import java.util.*; class Continue{ public static void main(String[] args){ Scanner scanner=new Scan ...
- B树详解
B树 具体讲解之前,有一点,再次强调下:B-树,即为B树.因为B树的原英文名称为B-tree,而国内很多人喜欢把B-tree译作B-树,其实,这是个非常不好的直译,很容易让人产生误解.如人们可能会以为 ...
- Nodejs与ES6系列4:ES6中的类
ES6中的类 4.1.class基本语法 在之前的javascript语法中是不存在class这样的概念,如果要通过构造函数生成一个新对象代码 function Shape(width,height) ...
- SWFObject Flash 增强插件
SWFObject 2提供两种优化flash播放器的嵌入方法:基于标记的方法和依赖于js的方法. SWFObject 2提供一个js的API,为嵌入SWF文件和获取Flash播放器的相关信息提供了一个 ...
- jQuery Panorama Viewer – 360度全景展示插件
jQuery Panorama Viewer 这款插件可以帮助你在网站中嵌入全景图片.要做到这一点,首先只需要在页面中引入最新的 jQuery 库,以及 jquery.panorama_viewer. ...
- requirejs:杏仁的优化(almond)
这里只是调侃一下,“杏仁”其实指的是almond,requirejs作者的另一个开源项目,它的定位是作为requirejs的一个替代品. 本文概要: 1. 使用场景 2. 打包例子:未使用almond ...
- JavaScript基础19——innerHTML示例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- SAP中日期时间函数总结
1.获得最后一天CALL FUNCTION 'FIMA_DATE_CREATE' EXPORTING I_DATE = I_DATE "输入 ...
- Web自动化测试 Selenium 3/3 https的配置
Https的信任问题处理 具体步骤如下(以demo为例) 1) ./ca.sh : 使用默认的服务器192.168.1.1的证书 ./ca.sh IP : 使用IP设置的证书 2) 以上运行后把 ge ...