当前位置:网站首页>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')
边栏推荐
- Shader basic UV operations, translation, rotation, scaling
- Particle effect for ugui
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- prometheus api删除某个指定job的所有数据
- Limit of total fields [1000] in index has been exceeded
- 用手机在通达信上开户靠谱吗?这样炒股有没有什么安全隐患
- Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
- A wave of open source notebooks is coming
- 121. 买卖股票的最佳时机
- When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
猜你喜欢
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
AB package details in unity (super detail, features, packaging, loading, manager)
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
Leetcode-231-2的幂
LeetCode3_ Longest substring without duplicate characters
Continuous creation depends on it!
Asynchronous application of generator function
Talk about the cloud deployment of local projects created by SAP IRPA studio
讲师征集令 | Apache SeaTunnel(Incubating) Meetup 分享嘉宾火热招募中!
20th anniversary of agile: a failed uprising
随机推荐
TCP framework___ Unity
What about the pointer in neural network C language
Detailed explanation of unity hot update knowledge points and introduction to common solution principles
Syntaxhighlight highlights the right scroll bar
Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
hellogolang
Three. JS introductory learning notes 15: threejs frame animation module
A link opens the applet code. After compilation, it is easy to understand
通知Notification使用全解析
分步式监控平台zabbix
Mesh merging under ue4/ue5 runtime
Mysql database backup script
Shader_ Animation sequence frame
Plate - forme de surveillance par étapes zabbix
Use moviepy Editor clips videos and intercepts video clips in batches
Dotween -- ease function
[excelexport], Excel to Lua, JSON, XML development tool
招标公告:2022年云南联通gbase数据库维保公开比选项目(第二次)比选公告
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
C4D learning notes 1- animation - animation key frames