SQL更优雅的布尔检查组合可能吗?

时间:2013-10-17 13:39:21

标签: sql

叫我迂腐但有没有更优雅的方式来结合所有这些检查?

SELECT * FROM [TABLE1] 
WHERE [path] = 'RECEIVE' 
AND [src_ip] NOT LIKE '10.48.20.10' 
AND [src_ip] NOT LIKE '0.%' 
AND [src_ip] NOT LIKE '127.%' 
ORDER BY [date],[time] DESC; 

对于这样的事情:

SELECT * FROM [TABLE1] 
WHERE [path] = 'RECEIVE' 
AND [src_ip] NOT LIKE IN ('10.48.20.10','0.%','127.%', .... ) 
ORDER BY [date],[time] DESC; 

2 个答案:

答案 0 :(得分:0)

您可以使用正则表达式。在MySQL中就像是

select * from [TABLE1]
where [path] = 'RECEIVE'
and [src_ip] not regexp '^(10\\.48\\.20\\.10$|0\\.|127\\.)'
order by [date], [time] desc

在Oracle中,它可能类似于

select * from [TABLE1]
where [path] = 'RECEIVE'
and not regexp_like([src_ip], '^(10\.48\.20\.10$|0\.|127\.)')
order by [date], [time] desc

答案 1 :(得分:0)