当前位置:网站首页>MySQL queries data by day, week, month, quarter and year
MySQL queries data by day, week, month, quarter and year
2022-06-25 23:15:00 【withoutfear】
1. Query today's data
SELECT * FROM Table name WHERE TO_DAYS( Time field name ) = TO_DAYS(NOW());2. Query yesterday's data
SELECT * FROM Table name WHERE TO_DAYS(NOW()) - TO_DAYS( Time field name ) <= 1;3. Query data of this week
SELECT * FROM Table name WHERE YEARWEEK(DATE_FORMAT( Time field name ,'%Y-%m-%d')) = YEARWEEK(NOW());4. Query last week's data
SELECT * FROM Table name WHERE YEARWEEK(DATE_FORMAT( Time field name ,'%Y-%m-%d')) = YEARWEEK(NOW())-1;5. Query near 7 Day data
SELECT * FROM Table name WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= DATE( Time field name );6. Query near 30 Day data
SELECT * FROM Table name WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE( Time field name );7. Query this month's data
SELECT * FROM Table name WHERE DATE_FORMAT( Time field name ,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m');8. Query the data of last month
SELECT * FROM Table name WHERE PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT( Time field name ,'%Y%m')) = 1;
SELECT * FROM Table name WHERE DATE_FORMAT( Time field name ,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') ;
SELECT * FROM Table name WHERE WEEKOFYEAR(FROM_UNIXTIME( Time field name ,'%y-%m-%d')) = WEEKOFYEAR(NOW());
SELECT * FROM Table name WHERE MONTH(FROM_UNIXTIME( Time field name ,'%y-%m-%d')) = MONTH(NOW());
SELECT * FROM Table name WHERE YEAR(FROM_UNIXTIME( Time field name ,'%y-%m-%d')) = YEAR(NOW()) AND MONTH(FROM_UNIXTIME( Time field name ,'%y-%m-%d')) = MONTH(NOW());9. Query near 6 Monthly data
SELECT * FROM Table name WHERE Time field name BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW();10. Query this quarter's data
SELECT * FROM Table name WHERE QUARTER( Time field name ) = QUARTER(NOW());11. Query last quarter data
SELECT * FROM Table name WHERE QUARTER( Time field name ) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER));12. Query this year's data
SELECT * FROM Table name WHERE YEAR( Time field name )=YEAR(NOW());13. Query last year's data
SELECT * FROM Table name WHERE YEAR( Time field name ) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR));边栏推荐
- 使用EAST ocr遇到的坑解决方法(编译lanms)
- ES6 - numerical extension and object extension
- 一位博士在华为的22年
- Common MySQL database functions and queries
- Sword finger offer 46 Translate numbers to strings (DP)
- No absurd tea applet - rule change
- Unity技术手册 - GetKey和GetAxis和GetButton
- . SQL database import error: / *! 40101 SET @OLD_ COLLATION_ [email protected]@COLLATION_ CONNECTION */
- 如何用jmeter做接口测试
- Unity technical manual - getKey and getaxis and getbutton
猜你喜欢

What aspects should we start with in the feasibility analysis of dry goods?

2022年河南省第一届职业技能大赛网络安全项目试题

小程序绘制一个简单的饼图

Circuit module analysis exercise 5 (power supply)

Set up your own website (15)

再突破!阿里云进入Gartner云AI开发者服务挑战者象限

As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)

Basic concepts of processor scheduling

Use apiccloud AVM multi terminal component to quickly realize the search function in the app

22 years of a doctor in Huawei
随机推荐
ES6学习-- LET
. SQL database import error: / *! 40101 SET @OLD_ COLLATION_ [email protected]@COLLATION_ CONNECTION */
异或运算符简单逻辑运算 a^=b
Relinearization in homomorphic encryption (ckks)
多台云服务器的 Kubernetes 集群搭建
腾讯《和平精英》新版本将至:新增账号安全保护系统,游戏内违规行为检测升级
MySQL数据库常用函数和查询
牛客小白月赛52--E 分组求对数和(二分)
Network security project questions of the first Henan vocational skills competition in 2022
【EOSIO】EOS/WAX签名错误 is_canonical( c ): signature is not canonical 问题
Multi modal data can also be Mae? Berkeley & Google proposed m3ae to conduct Mae on image and text data! The optimal masking rate can reach 75%, significantly higher than 15% of Bert
Does jQuery cache any selectors- Does jQuery do any kind of caching of “selectors”?
zabbix_ Server configuration file details
Canoe: the fifth simulation project: simulation + test
Equivalence class, boundary value, application method and application scenario of scenario method
判断预约时间是否已经过期
As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)
Unity技术手册 - 粒子基础主模块属性-上
Meta universe standard forum established
万亿热钱砸向太空经济,真的是一门好生意?