sql 一般模糊查询语句,查询表T , 表T2的SEQ是条件,请问模糊查询 如何 能够匹配表T2的SEQ多个字符?

执行脚本,没有结果

;with T as(

select '09 22 25' notext
union all select '16 18 29' 
union all select '11 21 23' 
union all select '06 08 19' 
union all select '03 05 25' 
)
,T2 as(
select '25' SEQ
union all select '29' 
union all select '19'select notext from T where notext LIKE '% + select CAST(SEQ AS INT) from T2 + %' 

想得到的结果

notext
09 22 25
16 18 29
06 08 19
03 05 25

没这么复杂,使用 EXISTS子查询即可
以下SQL在MySQL 8中运行通过

WITH t AS (
        SELECT '09 22 25' notext UNION ALL
        SELECT '16 18 29' notext UNION ALL
        SELECT '11 21 23' notext UNION ALL
        SELECT '06 08 19' notext UNION ALL
        SELECT '03 05 25' notext UNION ALL
        SELECT '15 29 19' notext ) -- 这条数据,INNER JOIN 会输出 2 条一样的重复数据
    , t2 AS (
        SELECT '25' seq UNION ALL
        SELECT '29' seq UNION ALL
        SELECT '19' seq )
-- SELECT notext FROM t JOIN t2 ON t.notext LIKE concat( '%', t2.seq, '%' );
 SELECT notext FROM t WHERE EXISTS( SELECT 1 FROM t2 WHERE t.notext LIKE concat( '%', t2.seq, '%' ) );


使用楼上的 inner join 虽然在楼主的举例中能够输出正确结果,但如果 seq 中存在多次匹配(如上述SQL中的 '15 29 19’),则会导致多次重复的输出,需要哪种结果,需要看需求具体是怎样要求的


with T as(
select '09 22 25' notext,'A'flag
union all select '16 18 29' ,'A'flag
union all select '11 21 23' ,'A'flag
union all select '06 08 19' ,'A'flag
union all select '03 05 25' ,'A'flag
),
T2 as(
select '25' SEQ,'A'flag
union all select '29' ,'A'flag
union all select '19' ,'A'flag
)
select notext from T 
left join T2 ON T.flag=T2.flag
where charindex(T2.SEQ,T.notext)>0

PS:问题中代码有一个中文右括号,不知道你是咋运行的 - - !

with T as(
 
select '09 22 25' notext
union all select '16 18 29' 
union all select '11 21 23' 
union all select '06 08 19' 
union all select '03 05 25' 
)
, T2 as(
select '25' SEQ
union all select '29' 
union all select '19' 
)
select notext from T t inner join T2 t2 on notext like  CONCAT("%",SEQ,"%")

== 若有帮助,请采纳 ==

这里的重点不是如何模糊查询,而是如何动态传入条件,直接写不行的,变成字符串了
百度一下动态SQL,或者用函数来实现