当前位置:网站首页>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')边栏推荐
- Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
- numpy--疫情数据分析案例
- Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
- Introduction to pyGame games
- 2022山东智慧养老展,适老穿戴设备展,养老展,山东老博会
- Unity3D_ Class fishing project, bullet rebound effect is achieved
- TCP framework___ Unity
- 深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
- 121. 买卖股票的最佳时机
- 模仿企业微信会议室选择
猜你喜欢

分步式监控平台zabbix

Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation

Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"

Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping

SPI master RX time out interrupt

2022第四届中国(济南)国际智慧养老产业展览会,山东老博会

LeetCode1_ Sum of two numbers

LeetCode2_ Add two numbers

Plate - forme de surveillance par étapes zabbix

LeetCode3_ Longest substring without duplicate characters
随机推荐
How does geojson data merge the boundaries of regions?
Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
Postman generate timestamp, future timestamp
A JS script can be directly put into the browser to perform operations
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
Three. JS introductory learning notes 15: threejs frame animation module
招标公告:2022年云南联通gbase数据库维保公开比选项目(第二次)比选公告
AE learning 02: timeline
Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
A link opens the applet code. After compilation, it is easy to understand
【微信小程序】Chapter(5):微信小程序基础API接口
Summary of knowledge points of xlua hot update solution
js中复选框checkbox如何判定为被选中
121. The best time to buy and sell stocks
Communication mode between application program and MATLAB
Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
LeetCode1_ Sum of two numbers
Learn good-looking custom scroll bars in 1 minute
Introduction to pyGame games
应用程序和matlab的通信方式