[英]SQL SELECT WHERE NOT LIKE
I have an array: 我有一个数组:
$codes = array (97121, 97122, 97123, 97180);
The real array is much longer, it contains nearly 130 codes so I think it doesn't have to be a loop. 真正的数组更长,它包含近130个代码,所以我认为它不必是一个循环。
And I have a mySQL table that has a column VilleAnn
(city with postal code) ex: 我有一个mySQL表,其中有一个列VilleAnn
(带有邮政编码的城市)ex:
Using mysqli I have to select where VilleAnn
doesn't contain any postal code from the array $codes
. 使用mysqli我必须选择VilleAnn
不包含数组$codes
任何邮政编码。
If the VilleAnn
is a simple postal code I would say: 如果VilleAnn
是一个简单的邮政编码我会说:
SELECT * FROM table WHERE VilleAnn NOT IN(97121, 97122, 97123, 97180)
But in this case it must be something using NOT LIKE "%..."
但在这种情况下,它必须是使用NOT LIKE "%..."
Any suggestions? 有什么建议么?
你可以REGEXP:
SELECT * FROM table WHERE VilleAnn NOT REGEXP '97121|97122|97123|97180|....'
Something like this: 像这样的东西:
SELECT *
FROM `table`
WHERE (
`VilleAnn` NOT LIKE '%97121%' AND
`VilleAnn` NOT LIKE '%97122%' AND
`VilleAnn` NOT LIKE '%97123%' AND
`VilleAnn` NOT LIKE '%97180%'
)
In condition doesn't work with the wildcard characters. 在条件不适用于通配符。 Your best bet is to try and extract the postcode from the original field, in this example 您最好的选择是尝试从原始字段中提取邮政编码,在此示例中
SELECT * FROM table WHERE right(VilleAnn,5) NOT IN ('97121', '97122', '97123', '97180')
I presume real life is more complicated, so this might need to be adjusted to reflect the actual format of the field. 我认为现实生活更复杂,所以可能需要调整以反映该领域的实际格式。
SELECT * FROM table WHERE VilleAnn NOT REGEXP '[0-9]';
This will help you. 这会对你有所帮助。
For to check four times occurrences you can use: 要检查四次出现,您可以使用:
SELECT * FROM table WHERE VilleAnn NOT REGEXP '[0-9]{4}';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.