当前位置:网站首页>sql 一般模糊查询语句,查询表T , 表T2的SEQ是条件,请问模糊查询 如何 能够匹配表T2的SEQ多个字符?
sql 一般模糊查询语句,查询表T , 表T2的SEQ是条件,请问模糊查询 如何 能够匹配表T2的SEQ多个字符?
2022-04-21 08:38:00 【CSDN问答】
执行脚本,没有结果
;with T as(select '09 22 25' notextunion 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' SEQunion 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’),则会导致多次重复的输出,需要哪种结果,需要看需求具体是怎样要求的
版权声明
本文为[CSDN问答]所创,转载请带上原文链接,感谢
https://ask.csdn.net/questions/7691286
边栏推荐
- Leetcode0824. Goat Latin (simple, string processing)
- docker怎么访问宿主中redis服务6379端口
- 51 单片机学习_1.2 LED闪烁
- [reprint] explain Fourier transform in simple terms
- autojs连接不上电脑,提示连接失败,权限不足
- 【CVPR 2020】PointASNL :Robust Point Clouds Processing using Nonlocal Neural Networks
- Count the number of linked lists and look up linked lists
- [Tools]Pwn中用于远程交互的库函数总结
- Introduction to microservices: ribbon and Nacos
- 51 single chip microcomputer learning_ 1.2 LED flashing
猜你喜欢
![[arm assembly judgment] how to use assembly to judge the number of positive and negative numbers in an array?](/img/96/de72a6446ff1405697ff90369946ed.png)
[arm assembly judgment] how to use assembly to judge the number of positive and negative numbers in an array?

autojs自动化脚本怎么在电脑上开发, 详细的靠谱教程!!!

JVM——》CMS

逻辑回归----案例:癌症分类预测

According to the variable name we want to visit

内网渗透-代理穿透-提权-注入-msf-中间件-域渗透-日志清除-学习资源

Xilinx MPSoC Emio IIC construction

Power grid enterprise standard B interface access record (II): resource reporting

knn预测最小案例总结

7.3 convolutional neural network Nin
随机推荐
Convert n arrays into JSON form
机器学习笔记 - SVD奇异值分解(2)
Notice on printing and distributing the administrative measures for the first edition of software product certification in Hunan Province
7.4 并行卷积神经网络 GoogleNet
Signalr console as server
线性回归api
Don't be greedy for cheap. The free MES system is not necessarily good
Compile pyx file into PYD file (many pits have been solved)
正则表达式
Introduction to ACM [tree diameter]
7.3 convolutional neural network Nin
JVM——》G1垃圾收集器
Find the maximum common divisor and the minimum common multiple
答案为是或否的选项, 是使用一个复选框checkbox还是两个单选框radio? 哪个更合适? 为什么?
关于深度学习画图这件事
输入四个整数按照从小到大的顺序排列
【(强推)李宏毅2021/2022春机器学习课程】Unsupervised Learning - Linear Methods
网络电话VOIP技术解析
怎么获取png图片的创作者等信息, 不仅仅是文件大小等信息.即要怎么获取图片的元信息(metadata)
电网企标B接口接入记录(二):资源上报