当前位置:网站首页>String comparison size in MySQL (date string comparison problem)
String comparison size in MySQL (date string comparison problem)
2022-08-02 03:34:00 【asdfadafd】
String comparison size in MySQL (date string comparison problem)
In the database, when comparing the size of strings with numbers and non-numbers, If the lengths of the two strings are equal, then the two strings will comparison at the same position.Character , if the character is a number, it will be compared directly. If the character is not a number, it will be converted to ascii code for comparison.Compare.
As mentioned above, problems arise when strings are used to compare time-formatted data for time-dimension comparisons.When querying as the following sql
select * FROM work_day_content as wdc WHERE wdc.work_day >= '2019-09-30 00:00:00' AND wdc.work_day<= '2019-10-06 00:00:00'
Figure 1-1
As shown in Figure 1-1, no conditions were found
When using the date function to convert a string to a date
select * FROM work_day_content as wdc where date(wdc.work_day) >= date('2019-09-30 00:00:00' ) AND date(wdc.work_day)<= date('2019-09-30 00:00:00' )
Figure 1-2
As shown in Figure 1-2, the qualified data was found
Analyze why the first sql statement did not query the content.Since the field is stored in the form of a string, the comparison of the size is performed in the form of a string at this time.
The size of the string comparison is from left to right.When matching strings of different lengths.There is no size difference after the shorter strings are compared.longer strings are larger.As shown in the following sql
select '2019-09-30' < '2019-09-30 00:00:00'
It is found that the **string '2019-09-30 00:00:00'** is larger at this time.Therefore, the previous sql did not find the data dated 2019-09-30
Therefore.When using strings to represent time, you need to use the time function for comparison.
The time functions provided by sql are: date(), str_to_date()
In addition, in mysql, when adding, subtracting, multiplying and dividing between string types, the part of the number that starts with a number will be intercepted for operation. If there is no number in front of the string, the only value that can be intercepted is0, then the result of addition and subtraction is 0, and the result of multiplication and division is NULL.
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
边栏推荐
- Small program (necessary common sense for development) 1
- Redis笔记进阶篇:万字长文-整理Redis,各种知识点,建议收藏
- Week 7 Review
- LeetCode:1161. 最大层内元素和【BFS层序遍历】
- 「PHP基础知识」空值(null)的使用
- 小程序组件总结
- CV-Model [4]: MobileNet v3
- 磷脂-聚乙二醇-酰肼,DSPE-PEG-Hydrazide,DSPE-PEG-HZ,MW:5000
- 线性代数学习笔记3-1:矩阵与线性变换、常见矩阵(逆矩阵、伴随矩阵、正交矩阵等)
- UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu
猜你喜欢
MySQL两阶段提交串讲
LeetCode:1374. 生成每种字符都是奇数个的字符串【签到题】
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
PowerManagerService灭屏超时流程
UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu
mysql卸载详细教程
【程序人生】做了多年的运维,靠什么转行拿下12K+年终奖的薪资?
分布式领域最重要的一篇论文,到底讲了什么?
MySQL分区表详解
JVM学习----垃圾回收--G1
随机推荐
MySQL8.0与MySQL5.7差异分析
The difference between the knowledge question and answer session with the knowledge
错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:
getattr() function analysis
Mysql8.0安装教程
线性代数学习笔记3-1:矩阵与线性变换、常见矩阵(逆矩阵、伴随矩阵、正交矩阵等)
HCIP-第十一天-MPLS+BGP
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
@Autowired详解[email protected]在static属性上的使用
Redis笔记基础篇:6分钟看完Redis的八种数据类型
2022.7.30 js notes Operators and flow controllers, loops
通过PS 2021 将网页图标抠下来
Knowledge Engineering Assignment 2: Introduction to Knowledge Engineering Related Fields
mysql创建表
我的两周年创作纪念日
Redis笔记进阶篇:万字长文-整理Redis,各种知识点,建议收藏
Mysql8创建用户以及赋权操作
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
LeetCode:1161. 最大层内元素和【BFS层序遍历】
MySQL常见的索引