博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【转】MySQL时间函数的使用:查询本周、下周、本月、下个月份的数据
阅读量:4626 次
发布时间:2019-06-09

本文共 813 字,大约阅读时间需要 2 分钟。

转自:

MySQL时间函数的使用:查询本周、上周、本月、上个月份的数据【转】

/*今天*/

select * from 表名 where to_days(时间字段) = to_days(now());

 

/*昨天*/

select * from 表名 where to_days(now())-to_days(时间字段) = 1;

 

/*近7天*/

select * from 表名 where date_sub(curdate(), interval 7 day) <= date(时间字段);

 

/*查询距离当前现在6个月的数据*/

select * from 表名 where 时间字段 between date_sub(now(),interval 6 month) and now();

 

/*查询当前这周的数据*/

select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now());

 

/*查询上周的数据*/

select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now())-1;

 

/*查询当前月份的数据*/

select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(now(),'%Y-%m');

 

/*查询上个月的数据*/

select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(date_sub(curdate(), interval 1 month),'%Y-%m');

 

转载于:https://www.cnblogs.com/fzzl/archive/2013/01/10/2854796.html

你可能感兴趣的文章
settTimeout vs setInterval
查看>>
Vista, the evil OS in the world
查看>>
Leetcode 80.删除排序数组中的重复项 II By Python
查看>>
常用JS加密编码算法
查看>>
spring boot中常用的配置文件的重写
查看>>
【线性规划和网络流24题】
查看>>
犹抱琵琶半遮面-OC
查看>>
标题颜色
查看>>
Python学习--和 Oracle 交互(2)
查看>>
VxWorks启动过程详解(上) 分类: vxWorks ...
查看>>
GJB150-2009军用装备实验室环境试验方法新版标准
查看>>
js面象对象插件+历史管理
查看>>
Spark学习体系整理(基础篇、中级篇、高级篇所涉及内容)
查看>>
网络编程之进程3
查看>>
Visual Studio Code 工具使用教程
查看>>
linux下shellcode编写入门
查看>>
selenium入门环境之浏览器问题
查看>>
BA--三相异步电机_星三角降压启动
查看>>
VM虚拟机安装后的网络设置
查看>>
jQuery Alert Dialogs (Alert, Confirm, & Prompt代替方案)
查看>>