当前位置:网站首页>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')
边栏推荐
- Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)
- 谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
- Mesh merging under ue4/ue5 runtime
- torch. Numel action
- C Alibaba cloud OSS file upload, download and other operations (unity is available)
- prometheus api删除某个指定job的所有数据
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- Three. Introduction to JS learning notes 17: mouse control of 3D model rotation of JSON file
- Aerospace Hongtu information won the bid for the database system research and development project of a unit in Urumqi
- Enterprise log analysis system elk
猜你喜欢
Mesh merging under ue4/ue5 runtime
Three. JS introductory learning notes 05: external model import -c4d into JSON file for web pages
It's different for rich people to buy a house
LeetCode1_ Sum of two numbers
Three. JS introductory learning notes 03: perspective projection camera
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
Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
Mysql database basic operation DQL basic query
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
Logback日志框架第三方jar包 免费获取
随机推荐
Leetcode-136-只出现一次的数(用异或来解答)
招标公告:盘锦市人民医院盘锦医院数据库维保项目
分步式監控平臺zabbix
LeetCode3_ Longest substring without duplicate characters
Shader_ Animation sequence frame
招标公告:2022年云南联通gbase数据库维保公开比选项目(第二次)比选公告
Use moviepy Editor clips videos and intercepts video clips in batches
Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"
Particle effect for ugui
iptables只允许指定ip地址访问指定端口
20th anniversary of agile: a failed uprising
[excelexport], Excel to Lua, JSON, XML development tool
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
nodejs package. JSON version number ^ and~
2022山东智慧养老展,适老穿戴设备展,养老展,山东老博会
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
The unity vector rotates at a point
torch.numel作用
Description of vs common shortcut keys
Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)