如何模糊匹配多行数据

使用 REGEXP 与 GROUP_CONCAT

WITH t1 AS (
select 'AAA苹果AAA' as c1 union all
select 'BBB苹果BBB' as c1 union all
select 'CCC桃子CCC' as c1 union all
select 'DDD桃子DDD' as c1 union all
select 'EEE梨EEE' as c1
),
t2 AS (
select '苹果' as c1 union all
select '桃子' as c1
)

SELECT *
FROM t1
WHERE t1.c1 REGEXP(
  SELECT GROUP_CONCAT(t2.c1 SEPRARTOR "|")
  FROM t2
)
1 个赞