当前位置:网站首页>How to query the data of a certain day, a certain month, and a certain year in MySQL
How to query the data of a certain day, a certain month, and a certain year in MySQL
2022-07-07 16:12:00 【aGreetSmile】
MySQL in , How to query a day , Some month , Data for a certain year
today
select * from Table name where to_days( Time field name ) = to_days(now());
yesterday
SELECT * FROM Table name WHERE TO_DAYS( NOW( ) ) - TO_DAYS( Time field name ) <= 1
near 7 God
SELECT * FROM Table name where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date( Time field name )
near 30 God
SELECT * FROM Table name where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date( Time field name )
This month,
SELECT * FROM Table name WHERE DATE_FORMAT( Time field name , '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
Last month
SELECT * FROM Table name WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( Time field name , '%Y%m' ) ) =1
Query this quarter's data
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(now());
Query last quarter data
select * from `ht_invoice_information` where QUARTER(create_date)=QUARTER(DATE_SUB(now(),interval 1 QUARTER));
Query this year's data
select * from `ht_invoice_information` where YEAR(create_date)=YEAR(NOW());
Query the data of last year
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));
Query the current week's data
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());
Look up last week's data
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;
Look up last month's data
Copy code
Copy code
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 Last day of last month and The first day of next month
Copy code
Copy code
Query the data of the current month
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')
Query distance now 6 Months of data
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
Query the data of a month ( Inquire about 17 year 10 Monthly data )
select * from exam where date_format(starttime,'%Y-%m')='2017-10'
select * from exam where date_format(starttime,'%Y-%m')=date_format('2017-10-05','%Y-%m')边栏推荐
- Syntaxhighlight highlights the right scroll bar
- 修改配置文件后tidb无法启动
- C4D learning notes 2- animation - timeline and time function
- Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
- leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
- Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
- Sysom case analysis: where is the missing memory| Dragon lizard Technology
- Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
- Logback日志框架第三方jar包 免费获取
- Mesh merging under ue4/ue5 runtime
猜你喜欢

喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配

Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!

企业级日志分析系统ELK

星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”

Continuous creation depends on it!

Enterprise log analysis system elk

尤雨溪,来了!

Numpy --- basic learning notes

Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?

Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
随机推荐
MySQL中, 如何查询某一天, 某一月, 某一年的数据
AE learning 01: AE complete project summary
Please supervise the 2022 plan
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
招标公告:盘锦市人民医院盘锦医院数据库维保项目
three.js打造酷炫下雪效果
应用程序和matlab的通信方式
Three. JS introductory learning notes 05: external model import -c4d into JSON file for web pages
用手机在通达信上开户靠谱吗?这样炒股有没有什么安全隐患
Application example of infinite list [uigridview]
Unity drawing plug-in = = [support the update of the original atlas]
Notification uses full resolution
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
Numpy --- basic learning notes
121. 买卖股票的最佳时机
Async and await
Shader basic UV operations, translation, rotation, scaling
Three. JS introductory learning notes 00: coordinate system, camera (temporarily understood)
[excelexport], Excel to Lua, JSON, XML development tool
Three. JS introduction learning notes 12: the model moves along any trajectory line