[英]How can I use a list of wildcard match in SQL?
I have a SQL code:我有一个 SQL 代码:
CASE
WHEN job_title LIKE '%Temp%'
OR job_title LIKE '%Intern%'
OR job_title LIKE '%Substitute%' THEN true
ELSE false
END AS is_part_time,
I wanted to know if there is a cleaner way to do this, is it possible to use a list of wildcards similar to IN clause?我想知道是否有更简洁的方法来执行此操作,是否可以使用类似于 IN 子句的通配符列表? Something like this?是这样的吗?
CASE
WHEN job_title LIKE ['%Temp%','%Intern%','%Substitute%'] THEN true
ELSE false
END AS is_part_time,
You may consider using regular expressions and simplify this using RLIKE
eg您可以考虑使用正则表达式并使用RLIKE
简化它,例如
CASE
WHEN job_title RLIKE '.*(Temp|Intern|Substitute).*' THEN true
ELSE false
END AS is_part_time,
or simply或者简单地
job_title RLIKE '.*(Temp|Intern|Substitute).*' AS is_part_time
Let me know if this works for you.如果这对你有用,请告诉我。
You can phrase this using regular expressions:您可以使用正则表达式来表达这一点:
(job_title rlike 'Temp|Intern|Substitute') as is_part_time
Note: You should really have a table with valid job titles.注意:您确实应该有一个包含有效职位的表格。 That table should have columns that specify characteristics of the job, such as is_part_time
.该表应包含指定作业特征的列,例如is_part_time
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.