简体   繁体   English

如何将“IN”与字符串列表一起使用?

[英]How can I use `IN` with a list of strings?

图片

I am trying to replace semicolon-separated strings(;) with comma-separated strings(,) in the where condition and have tried this in the where clause but I do not work.我试图在 where 条件中用逗号分隔的字符串(,)替换分号分隔的字符串(;),并在 where 子句中尝试过,但我不工作。 Can anyone help me with the solution?谁能帮我解决问题?

s.securitydepartment in (REPLACE('Leverkusen;Waterford',';',','))

As mentioned in the comments, what you probably want is something like this:正如评论中提到的,你可能想要的是这样的:

SELECT {Your Columns}
FROM {Your Table} YT
     JOIN STRING_SPLIT('Leverkusen;Waterford',';') SS ON YT.securitydepartment = SS.[Value]
WHERE ...

Of course, however, as 'Leverkusen;Waterford' is a literal though, why not just fix the query and do:但是,当然,由于'Leverkusen;Waterford'是字面意思,为什么不直接修复查询并执行以下操作:

s.securitydepartment IN ('Leverkusen','Waterford')

In is a operator that works on a set , not a string. In是一个适用于集合的运算符,而不是字符串。

You need to provide a set of values, a string is not "parsed" in any way or treated as a comma-separated list.您需要提供一组值,字符串不会以任何方式“解析”或视为逗号分隔的列表。

You can use string_split to return a set of values, for example您可以使用string_split返回一组值,例如

and s.securityDepartment in (select value from string_split('value1;value2;value3',';'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在字符串列表中使用LIKE运算符进行比较? - How can I use the LIKE operator on a list of strings to compare? 如何将 JSON 字典列表转换为 Snowflake 中的字符串列表? - How can I convert a JSON list of dicts to a list of strings in Snowflake? 如何正确使用 DLookup function 返回字符串? - How can i properly use DLookup function to return strings? 如何在 sql 查询中使用字符串列表 - how to use a list of strings in a sql query SQL-如何在字符串列表中找到确切的字符串,该字符串可以是列表中另一个字符串的一部分? - SQL - How do I find the exact string in a list of strings that can be part of another string in the list? 如何在 SQL 中使用通配符匹配列表? - How can I use a list of wildcard match in SQL? 如何在 SQL Where IN 子句中使用 Python 列表? - How can I use a Python List in a SQL Where IN Clause? 如何使用 Max Function 过滤列表并插入 - How Can I Use the Max Function to Filter a List and Insert Into 我可以使用什么子查询根据字符串过滤数据? - What subquery can I use to filter data depending on strings? 使用 Python - 如何解析整数和字符串的 CSV 列表并通过插入语句添加到 SQL 表? - Using Python - How can I parse CSV list of both integers and strings and add to SQL table through Insert Statement?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM