当前位置:网站首页>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')边栏推荐
- Dotween -- ease function
- 统计学习方法——感知机
- Plate - forme de surveillance par étapes zabbix
- LeetCode1_ Sum of two numbers
- Description of vs common shortcut keys
- 强化实时数据管理,英方软件助力医保平台安全建设
- AB package details in unity (super detail, features, packaging, loading, manager)
- Asynchronous application of generator function
- Ue4/ue5 multi thread development attachment plug-in download address
- Unity drawing plug-in = = [support the update of the original atlas]
猜你喜欢

Leetcode-231-2的幂

过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?

Three. JS introductory learning notes 04: external model import - no material obj model

numpy---基础学习笔记

The unity vector rotates at a point

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

Plate - forme de surveillance par étapes zabbix

山东老博会,2022中国智慧养老展会,智能化养老、适老科技展

统计学习方法——感知机

Ue4/ue5 multi thread development attachment plug-in download address
随机推荐
nodejs package. JSON version number ^ and~
Whole process analysis of unity3d rendering pipeline
121. The best time to buy and sell stocks
航运船公司人工智能AI产品成熟化标准化规模应用,全球港航人工智能/集装箱人工智能领军者CIMC中集飞瞳,打造国际航运智能化标杆
Three. JS introductory learning notes 11:three JS group composite object
Syntaxhighlight highlights the right scroll bar
Unity3D_ Class fishing project, bullet rebound effect is achieved
过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?
招标公告:福建省农村信用社联合社数据库审计系统采购项目(重新招标)
A link opens the applet code. After compilation, it is easy to understand
Function: JS Click to copy content function
hellogolang
Plate - forme de surveillance par étapes zabbix
无线传感器网络--ZigBee和6LoWPAN
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
numpy--数据清洗
numpy---基础学习笔记
Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
【花雕体验】15 尝试搭建Beetle ESP32 C3之Arduino开发环境