我可以用它来查找有问题的所有行:
select * from `full_local_demographic` where length(fips) < 5
这些查找 fips
少于 5 个字符的所有行。这些应该都是 5 个字符。当它们上传时,数据不正确并且丢失了前导零。我需要在 mysql 查询中添加什么,以便将上述查询找到的所有 fips
条目的零添加到前面?
最佳答案
您可以只使用lpad()
select lpad(fips, 5, '0')
from full_local_demographic
您甚至不需要 where
子句。如果您想更新值,那么建议使用 where
子句:
update full_local_demographic
set fips = lpad(fips, 5, '0')
where length(fips) < 5;
关于mysql - 向与我的过滤器匹配的所有条目添加零(mysql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30293559/