gpt4 book ai didi

Sql Server 在另一个字符串中查找部分字符串

转载 作者:行者123 更新时间:2023-12-02 22:30:19 25 4
gpt4 key购买 nike

我有一张 table

studentId        Classes
1 Auto CAD,Electronics
2 Instrumentation,Chemical,IT,English
3 Computer,Math,Hindi
4 Physics,Accountancy
5 Bengali,Geography

现在我想使用单个字符串“Instrumentation,Geography,Physics”进行搜索

会显示以下内容

studentId        Classes
2 Instrumentation,Chemical,IT,English
4 Physics,Accountancy
5 Bengali,Geography

因为 studentid 2 包含 Instrumentation,studentid 4 包含 Physics,而 studentid 5 包含 Geography

如何使用 SELECT 语句来实现?不像类 '%Instrumentation%'或像“%Geography%”或像“%Physics%”这样的类,因为我想使用单个变量来字符串“Instrumentation、Geography、Physics”或以逗号分隔的字符串的任意组合。

最佳答案

试试这个:

SELECT * 
FROM your_Table
WHERE ','+Classes+',' like '%,Instrumentation,%'
OR ','+Classes+',' like '%,Geography,%'
OR ','+Classes+',' like '%,Physics,%'

我在列和搜索条件中添加了一个逗号,这样它将只返回以逗号结尾的字符串

关于Sql Server 在另一个字符串中查找部分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12384334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com