-- 查询今天的数据

select * from `user` where to_days(birthday) = to_days(CURDATE());

-- 查询昨天的数据

select * from `user` where to_days(CURDATE()) - to_days(birthday)<=1;

-- 查询最近7天的数据

select * from `user` where birthday > DATE_SUB(CURDATE(),INTERVAL 7 DAY);

-- 查询最近一个季度的数据

select * from `user` where birthday > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)

-- 最近一年的数据

select * from `user` where birthday > DATE_SUB(CURDATE(), INTERVAL 1 YEAR);

 

-- 本季度的数据

select * from `user` where quarter(birthday) = quarter(CURDATE());

-- 上季度的数据

select * from `user` where quarter(birthday) = quarter(DATE_SUB(CURDATE(), INTERVAL 1 QUARTER));

 

-- 查询今年的数据

select * from `user` where year(CURDATE()) - year(birthday) = 28 ;

 

-- 查询第几月的数据

select * from `user` where month(birthday) = 8 ;

 

-- 查询某年某月某日的数据

select * from `user` where date_format(birthday,'%Y-%m-%d')='2017-07-07';

 

-- 查询制定时间段内的数据(只写到月,会出错)

select * from `user` where birthday between '1888-5-1 00:00:00' and '2017-9-3 00:00:00';

 

-- 查询制定时间段内的数据(只写到月,会出错)

select * from `user` where birthday > '1989-5-1' and birthday < '2017-5-1';

MySQL—查询某时间范围的数据的更多相关文章

  1. mysql查询随机几条数据(速度快)

    MySql查询随机几条数据 想到了 Max RAND 这几个函数 用以下2种办法都可以实现查询. 速度还行. 几十万数据左右, 没有什么问题. SELECT * FROM `news` WHERE i ...

  2. mysql查询进程、导入数据包大小设置

    mysql查询进程.导入数据包大小设置 zoerywzhou@163.com http://www.cnblogs.com/swje/ 作者:Zhouwan 2017-12-27 查询正在执行的进程: ...

  3. mysql查询表里的重复数据方法:

    INSERT INTO hk_test(username, passwd) VALUES ('qmf1', 'qmf1'),('qmf2', 'qmf11') delete from hk_test  ...

  4. mysql 查询一个月的数据

    //今天 select * from 表名 where to_days(时间字段名) = to_days(now()); //昨天 SELECT * FROM 表名 WHERE TO_DAYS( NO ...

  5. mysql查询包含逗号的数据,并逗号拆分为多行展现

    在做系统开发的时候,有可能是由于之前的遗留问题,导致在数据入库的时候,将多个数据以逗号分隔的实行,存储在一条数据中,例如: ID VALUE 1 yang,zheng,song 2 zhao,qian ...

  6. MySQL查询和删除重复数据

    删除表中重复记录,只保留一条: delete from 表名 where 字段ID in (select * from (select max(字段ID) from 表名 group by 重复的字段 ...

  7. MySQL查询指定时间的数据

    user_event :用户事件表 create_time :表中存储时间的字段 #获取当月数据 SELECT * FROM user_event WHERE DATE_FORMAT(create_t ...

  8. mysql 查询近7天数据,缺失补0

    相信很多人的项目都有这种需求,就是查询近7天的记录,但是这7天总有那么几天是没数据的,所以缺失的只能补 0 下面的代码不知道能不能看懂,我简单的说一下思路 1)先查询红色字体的近7天,再转换成日期 2 ...

  9. mysql查询哪张表数据最大

    转载:https://blog.csdn.net/qq13650793239/article/details/81142134 mysql数据库中information_schema 数据库存储了数据 ...

随机推荐

  1. python成功之道

    https://blog.ansheng.me/article/python-full-stack-way

  2. SpringBoot配置(2) slf4j&logback

    SpringBoot配置(2) slf4j&logback 一.SpringBoot的日志使用 全局常规设置(格式.路径.级别) SpringBoot能自动适配所有的日志,而且底层使用slf4 ...

  3. 【动态规划】最大连续子序列和,最大子矩阵和,最大m子段和

    1.最大字段和问题 求一个序列最大连续子序列之和. 例如序列[-1,-2,-3,4,5,-6]的最大子段和为4 + 5 = 9. ①枚举法 int MaxSum(int n,int *a){ int ...

  4. python内置函数,匿名函数

    一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...

  5. css变换与动画详解

    举个栗子:--------元素整体居中.box{     position:absolute;top:50%;left:50%;    width:50px;    height:50px;    t ...

  6. Mac搭建kubernetes dashboard全流程

    1. 下载dashboard文件: curl -o kubernetes-dashboard.yaml https://raw.githubusercontent.com/kubernetes/das ...

  7. cookie与session的区别是什么

    cookie与session的区别有:cookie以文本格式存储在浏览器上,存储量有限:而会话存储在服务端,可以无限量存储多个变量并且比cookie更安全 在php中可以指定站点的访问者信息存储在se ...

  8. spring 生命周期最详解

    转载. https://blog.csdn.net/qq_23473123/article/details/76610052 目的 在大三开始学习spring时,老师就说spring bean周期非常 ...

  9. 获取mysql 配置和目录

    http://bbs.csdn.net/topics/390620630 mysql> show variables like '%dir%';+------------------------ ...

  10. 【转】完整精确导入Kernel与Uboot参与编译了的代码到Source Insight,Understand, SlickEdit

    The linux kernel and u-boot contains lots of files, when we want to broswe the source code,we just w ...