gpt4 book ai didi

mysql - 在where子句中操作字符串

转载 作者:行者123 更新时间:2023-11-29 14:03:21 25 4
gpt4 key购买 nike

我有一个变量list_name,其中包含以“:”分隔的名称列表

list_name=(rahul:john:steve) => list_name is of type 'string'

该列表包含 1000 个名称无法更改 list_name,因为我们从其他部门/公司获取它

想要编写一个查询来达到如下所示的目的,但为此需要进行字符串操作,即根据分隔符“:”从 list_names 中提取名称

从学生中选择roll_no其中名字是 rahul 或 john 或 steve (问题部分)

建议在sql中使用一些字符串操作技术从字符串中提取名称

PS:我使用的是专有 SQL,不支持循环

最佳答案

您可以使用标准 SQL 来执行此操作:

 select roll_no
from students
where concat(':', list_name, ':') like concat('%:', names, ':%')

在某些数据库中,where 可能写为:

 where ':'+ list_name+':' like '%:'+names+':%'

 where ':'|| list_name||':' like '%:'||names||':%'

关于mysql - 在where子句中操作字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14743465/

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