mysql如何限制sql查询时间


当前第2页 返回上一页

今天

1

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

昨天

1

SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <= 1

近7天

1

SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)

近30天

1

SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名)

本月

1

SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, ‘%Y%m’ ) = DATE_FORMAT( CURDATE( ) , ‘%Y%m’ )

上一月

1

SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , ‘%Y%m’ ) , date_format( 时间字段名, ‘%Y%m’ ) ) =1

查询本季度数据

1

select * from ht_invoice_information where QUARTER(create_date)=QUARTER(now());

查询上季度数据

1

select * from ht_invoice_information where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));

查询本年数据

1

select * from ht_invoice_information where YEAR(create_date)=YEAR(NOW());

查询上年数据

1

select * from ht_invoice_information where year(create_date)=year(date_sub(now(),interval 1 year));

查询当前这周的数据

1

SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now());

查询上周的数据

1

SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,’%Y-%m-%d’)) = YEARWEEK(now())-1;

查询上个月的数据

1

2

3

4

5

6

select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(DATE_SUB(curdate(), INTERVAL 1 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 下月第一天

查询当前月份的数据

1

select name,submittime from enterprise where date_format(submittime,’%Y-%m’)=date_format(now(),’%Y-%m’)

相关免费学习推荐:php编程(视频)

以上就是mysql如何限制sql查询时间的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

navicat 8 for mysql怎么用语句建表

oracle和mysql的高可用方案对比分析

mysql 权限控制细节分析

怎么看电脑里有没有mysql

六天带你玩转mysql视频教程资源推荐

mysql怎么创建存储函数

mysql workbench如何导出查询结果?(图文)

mysql数据库优化之索引实现原理与用法分析

mysql数据库系统特权如何查看?

详解mysql实现主从复制过程_mysql实例详解

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...