SQL查询,其中NOT IN使用LIKE或REGEXP

时间:2014-01-06 14:35:47

标签: mysql sql

我有下表。

如何返回IP_ADD不包含12.23.34.XX,13.23.34.XX,12.23.35.27或13.23.35.27的所有行,其中XX代表任何数字?

例如,使用此数据时,只应返回最后两行。

+----+---------------+
| ID |    IP_ADD     |
+----+---------------+
|  1 | '12.23.34.45' |
|  2 | '12.23.34.46' |
|  3 | '12.23.34.47' |
|  4 | '12.23.34.48' |
|  5 | '13.23.34.45' |
|  6 | '13.23.34.46' |
|  7 | '13.23.34.47' |
|  8 | '13.23.34.48' |
|  9 | '12.23.35.27' |
| 10 | '13.23.35.27' |
| 11 | '13.33.34.45' |
| 12 | '13.33.34.45' |
+----+---------------+

1 个答案:

答案 0 :(得分:2)

试试这个:

SELECT * FROM myTable 
where 
not  (IP_ADD in  ('12.23.35.27', '13.23.35.27') or 
IP_ADD like ('12.23.34.%') or
IP_ADD like ('13.23.34.%'));