对于数据库查询中条件匹配的几种解决方法:
简单方法 1 :使用or, between a and b, in 等
use 'or':
select a, b from test_table
where a = 'x' or a = 'y';
use 'between'
select a, b from test_table
where a between 1 and 3;
-- a 在闭合空间[1, 3]
select a, b from test_table
where a in (1, 2, 3)
-- a 等于1 或 2 或 3 都满足条件
简单方法 2 : 使用模糊匹配 like 或 rlike(mysql, hive)
select a, b from test_table
where a like '%hi%';
--匹配a中出现hi的数据行
对于like 需要记住一些常用匹配符,如
select a, b from test_table
where a rlike 'hi';
--匹配a中出现hi的数据行