我在邮政编码列上使用 SQL 进行查询,以检查列邮政编码中的哪些记录与使用 like 子句的格式不匹配。
我尝试查找与格式匹配的记录数。然后我尝试了哪些 zip 记录中有连字符或“-”。计数不同。
我想找出哪些记录是带有连字符'-'并且不符合XXXXX-XXXX格式的记录。
此外,我认为“^”否定符号在这里不起作用,因为它不在方括号“[]”中。试过了,但没有用
我试过的查询:
从 zipcode_table 中选择 count(*),其中 zipcode_column like '%-%'
从 zipcode_table 中选择 count(*),其中 zipcode_column like '_____-____'
最佳答案
你似乎想要:
select count(*)
from zipcode_table
where zipcode_column like '%-%' and -- has a hyphen
zipcode_column not like '_____-____'; -- but not in the right place
您可能真的想检查其他位置的数字:
where zipcode_column like '%-%' and -- has a hyphen
zipcode_column !~ '^[0-9]{5}-[0-9]{4}$'; -- but not in the right
关于sql - 如何找出具有特殊字符的记录不匹配具有相同特殊字符的格式类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55937998/