当前位置:网站首页>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 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
- Three. JS introductory learning notes 04: external model import - no material obj model
- [wechat applet] Chapter (5): basic API interface of wechat applet
- Unity3d click events added to 3D objects in the scene
- 95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
- Regular expression string
- 深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
- Three. Introduction to JS learning notes 17: mouse control of 3D model rotation of JSON file
- 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"?
- AB package details in unity (super detail, features, packaging, loading, manager)
猜你喜欢
统计学习方法——感知机
Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
Notification uses full resolution
numpy---基础学习笔记
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
What about the pointer in neural network C language
航运船公司人工智能AI产品成熟化标准化规模应用,全球港航人工智能/集装箱人工智能领军者CIMC中集飞瞳,打造国际航运智能化标杆
Postman generate timestamp, future timestamp
Unity drawing plug-in = = [support the update of the original atlas]
Sysom case analysis: where is the missing memory| Dragon lizard Technology
随机推荐
js中复选框checkbox如何判定为被选中
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
LeetCode1_ Sum of two numbers
C Alibaba cloud OSS file upload, download and other operations (unity is available)
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
L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
Continuous creation depends on it!
神经网络c语言中的指针是怎么回事
Whole process analysis of unity3d rendering pipeline
121. The best time to buy and sell stocks
统计学习方法——感知机
prometheus api删除某个指定job的所有数据
iptables只允许指定ip地址访问指定端口
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
LeetCode2_ Add two numbers
hellogolang
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
深度之眼(六)——矩阵的逆(附:logistic模型一些想法)