`SELECT * FROM my_table WHERE textfield >= "whatever";` 返回的行数是否多于 `count("whatever")` 行,因为它是一个数组?
我只是想知道为什么
CREATE TABLE employeeinfo(
position CHAR(50),
salary INT NOT NULL,
branch CHAR(50)
) ENGINE=InnoDB;
SELECT * FROM EMPLOYEEINFO
WHERE position >= 'Regional Manager';
要返回表中的每个人。
是因为它是某种数组吗?这不是按字母顺序排列的事情。难道是因为内存中的值大于区域经理内存中的值?我想有人告诉我这是因为内存中指针位置之间的差异?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关系数据库中不存在数组这样的东西。
如果该语句返回每个条目,那是因为条件的计算结果始终为 true。这意味着
position
始终 >= 字符串“Regional Manager”,因此任务是确定为什么会出现这种情况。如果
position
具有文本类型,则比较是字符串比较,因此诸如 'S' 之类的内容将 >= 'Regional Manager'。字符串比较取决于编码(在MySQL 术语)和用于列的 排序规则。排序规则确定各个字符的顺序。此外,对于大多数情况,MySQL 默认使用不区分大小写的比较排序规则,因此'a' < “区域经理”
,但's' >=“区域经理”
。如果
position
包含一个数值,那么 MySQL 将将“区域经理”转换为数字,使用尽可能多的字符串开头可解释为数字的数字:如果是这种情况,则只要
position
为积极,它将 >= '区域性 经理'。There's no such thing as an array in relational databases.
If the statement is returning every entry, it's because the condition always evaluates to true. This implies that
position
is always >= the string 'Regional Manager', so the task is to determine why this is the case.If
position
has a text type, then the comparison is a string comparison, so something such as 'S' would be >= 'Regional Manager'. String comparisons depend on the encoding (called "character set" in MySQL parlance) and collation used for the column. The collation determines the order for individual characters. Additionally, MySQL uses case insensitive comparisons by default for most collations, so'a' < 'Regional Manager'
but's' >= 'Regional Manager'
.If
position
holds a numeric value, then MySQL will convert 'Regional Manager' to a number using as much as the beginning of the string as can be interpreted as a number:If this is the case, then as long as
position
is positive, it will be >= 'Regional Manager'.