Sql 如何查找特殊字符与具有相同特殊字符的格式类型不匹配的记录?

Sql 如何查找特殊字符与具有相同特殊字符的格式类型不匹配的记录?,sql,postgresql,zip,postgis,street-address,Sql,Postgresql,Zip,Postgis,Street Address,我在邮政编码列上使用SQL查询,以检查列zipcodes中的哪些记录与使用like子句的格式不匹配 我尝试查找与格式匹配的记录数。然后我尝试了哪些zip记录中有连字符或“-”。计数不同 我想找出哪些记录是带有连字符“-”且与XXXXX-XXXX格式不匹配的记录 此外,我认为“^”否定符号在这里不起作用,因为它不在方括号“[]”中。我试过了,但没有成功 我尝试过的问题: 从zipcode_表中选择count(*),其中zipcode_列类似“%-%” 从zipcode_表中选择count(*),z

我在邮政编码列上使用SQL查询,以检查列zipcodes中的哪些记录与使用like子句的格式不匹配

我尝试查找与格式匹配的记录数。然后我尝试了哪些zip记录中有连字符或“-”。计数不同

我想找出哪些记录是带有连字符“-”且与XXXXX-XXXX格式不匹配的记录

此外,我认为“^”否定符号在这里不起作用,因为它不在方括号“[]”中。我试过了,但没有成功

我尝试过的问题:

从zipcode_表中选择count(*),其中zipcode_列类似“%-%”

从zipcode_表中选择count(*),zipcode_列如“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

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 
你似乎想要:

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 
选择
将(*)算作全部,
计数(*)过滤器(其中zipcode如“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu,
计数(*)筛选器(其中类似于“%-%”的zipcode和不类似于“u_____”)的zipcode的格式不正确,
将(*)筛选器(其中zipcode与“%-%”不同)计数为无连字符
从zipcode
选择
将(*)算作全部,
计数(*)过滤器(其中zipcode如“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu,
计数(*)筛选器(其中类似于“%-%”的zipcode和不类似于“u_____”)的zipcode的格式不正确,
将(*)筛选器(其中zipcode与“%-%”不同)计数为无连字符
从zipcode

感谢您的高质量回复,戈登。美元的符号是什么?此外,还有一个“^”、一个“not”和一个按位not“~”。你能帮我弄明白这是怎么回事吗?@VishwalShah。这些是正则表达式构造。嗯,
~
~分别是正则表达式匹配和不匹配的Postgres构造。正则表达式本身中的
^
$
用于在字符串的开头和结尾锚定模式(即匹配整个字符串)。感谢您的高质量响应,Gordon。美元的符号是什么?此外,还有一个“^”、一个“not”和一个按位not“~”。你能帮我弄明白这是怎么回事吗?@VishwalShah。这些是正则表达式构造。嗯,
~
~分别是正则表达式匹配和不匹配的Postgres构造。正则表达式本身中的
^
$
用于在字符串的开头和结尾锚定模式(即,匹配整个字符串)。