[英]mysql SELECT with SUBSTRING, LOWER and REPLACE commands
Im trying to do a select on the company name(cpnm) field of our company table but only giving me the first 6 characters, replacing all spaces plus making it lowercase. 我试图在公司表的公司名称(cpnm)字段上进行选择,但只给我前6个字符,替换所有空格并使其小写。
SELECT *,
SUBSTRING(LOWER(cpnm), -LENGTH(cpnm), 6) as test
FROM company
LIMIT 100
The above works fine but as soon as I try to add the replace spaces (shown below), it doesnt give back results. 上面的工作正常,但是一旦我尝试添加替换空间(如下所示),它就不会返回结果。
SELECT *,
SUBSTRING(LOWER(REPLACE(cpnm, ' ', '')), -LENGTH(cpnm), 6) as test
FROM company
LIMIT 100
Any ideas? 有任何想法吗?
I guess by replacing the spaces you change the length of the string, therefore substr()
doesn't work like you expect it. 我猜想通过替换空格可以更改字符串的长度,因此substr()
不能像您期望的那样工作。
Try SELECT *, SUBSTRING(LOWER(REPLACE(cpnm, ' ', '')), -LENGTH(REPLACE(cpnm, ' ', '')), 6) as test
instead! 尝试SELECT *, SUBSTRING(LOWER(REPLACE(cpnm, ' ', '')), -LENGTH(REPLACE(cpnm, ' ', '')), 6) as test
代替!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.