当前位置:网站首页>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')
边栏推荐
- Notification uses full resolution
- 强化实时数据管理,英方软件助力医保平台安全建设
- 统计学习方法——感知机
- C4D learning notes 1- animation - animation key frames
- Sysom case analysis: where is the missing memory| Dragon lizard Technology
- 通知Notification使用全解析
- 航天宏图信息中标乌鲁木齐某单位数据库系统研发项目
- Introduction to pyGame games
- Shader basic UV operations, translation, rotation, scaling
- laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
猜你喜欢
numpy--疫情数据分析案例
Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)
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
MySQL数据库基本操作-DQL-基本查询
You Yuxi, coming!
20th anniversary of agile: a failed uprising
LeetCode3_ Longest substring without duplicate characters
Postman generate timestamp, future timestamp
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
随机推荐
Three singleton modes of unity (hungry man, lazy man, monobehavior)
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
hellogolang
Please supervise the 2022 plan
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
Bidding announcement: 2022 Yunnan Unicom gbase database maintenance public comparison and selection project (second) comparison and selection announcement
Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
Virtual memory, physical memory /ram what
Mysql database backup script
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
Async and await
Unity drawing plug-in = = [support the update of the original atlas]
航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
Three. JS introductory learning notes 13: animation learning
When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
分步式监控平台zabbix
MySQL数据库基本操作-DQL-基本查询
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
招标公告:盘锦市人民医院盘锦医院数据库维保项目
Migration and reprint