当前位置:网站首页>Range query based on date in MySQL
Range query based on date in MySQL
2022-08-01 14:31:00 【Programmer over time】
1. Query the data of a certain year and a certain month in MySQL
The test data is as follows;
1.1 Query 2018 data:
select * from day_rate where year(date)='2018'
1.2 Query data for February:
select * from day_rate where month(date)='02'
1.3 Query data for February 2019:
select * from day_rate where year(date)='2019' and month(date)='02'
1.4 Query the data on the 32nd day of the beginning of the year:
select * from day_rate where dayofyear(date)='32'
Query the data of a certain year and a certain month in MySQL
2. The date range query cannot exceed the maximum date of a month
It seems to be mysql8. When using between...and... query, when the right boundary of the query is 2021-2-31, it exceeds the actual range (because there can be no 31 days in February), so the query cannot be performed.
Example:
select * from t_ordersetting where orderDate between '2021-09-01' and '2021-09-31';This method does not work, because there is no 31st in September, which exceeds the maximum date of September, so the query is wrong.
Solution:
Method 1 (verified and feasible):
Use select * from t_ordersetting where year(orderDate)=#{year} and month(orderDate)=#{month}; Query the data of a certain month and a certain year, as follows:
Method 2 (check the comments, it is not verified, I don't know if it is feasible):
Use: SELECT * FROM t_ordersetting WHERE orderDate BETWEEN STR_TO_DATE('2021-04-1','%Y-%m-%d') AND STR_TO_DATE('2021-04-31','%Y-%m-%d')
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- ABC260 E - At Least One(双指针)
- iPhone难卖,被欧洲反垄断的服务业务也难赚钱了,苹果的日子艰难
- 台积电认清了形势,新的建厂计划没有美国,中国芯片也得到重视
- 【论文笔记】MiniSeg: An Extremely Minimum Network for Efficient COVID-19 Segmentation
- 关于Request复用的那点破事儿。研究明白了,给你汇报一下。
- stm32l476芯片介绍(nvidia驱动无法找到兼容的图形硬件)
- Two Permutations
- PAT 1163 Dijkstra Sequence(30)
- HTB-Mirai
- OpenSSL SSL_read: Connection was reset, errno 10054
猜你喜欢

沃文特生物IPO过会:年营收4.8亿 养老基金是股东

立新能源深交所上市:市值55亿 哈密国投与国有基金是股东

响应式2022英文企业官网源码,感觉挺有创意的

gpio analog serial communication
![[LiteratureReview]Optimal and Robust Category-level Perception: Object Pose and Shape Estimation f](/img/bc/f3cea50c157f151a1ca5e540e7f77b.png)
[LiteratureReview]Optimal and Robust Category-level Perception: Object Pose and Shape Estimation f

PAT1166 Summit(25)

lua脚本关键

mysql查询两个字段值相同的记录

荣信文化通过注册:年营收3.8亿 王艺桦夫妇为实控人

openEuler 社区完成首批顾问专家聘用,共同为社区的发展贡献力量
随机推荐
代理商替代义隆153 Aip4210
可观测性就是对“监控”的包装?
我寻找的方向
The little thing about Request reuse.The research is understood, and I will report it to you.
使用open3d可视化3d人脸
沃文特生物IPO过会:年营收4.8亿 养老基金是股东
HTB-Mirai
Qt实战案例(56)——利用QProcess实现应用程序重启功能
牛客刷SQL--4
Performance Optimization - Resource Optimization Notes
长江欧拉生态创新中心成立,武汉数字经济再添坚实底座
【论文笔记】MiniSeg: An Extremely Minimum Network for Efficient COVID-19 Segmentation
PAT1166 Summit(25)
docker部署mysql并修改其占用内存大小
Performance Optimization - Animation Optimization Notes
易优压双驱挖掘机压路机器类网站源码 v1.5.8
MBI5020 LED驱动
ECCV 2022|R2L: 用数据蒸馏加速NeRF
超全!全国近90所大学考研报录比汇总!
全球都热炸了,谷歌服务器已经崩掉了