SQL "NOT LIKE" 在一行中尽可能减少 NOT LIKE
SQL "NOT LIKE" reduce as many NOT LIKE as you can in a single line
我有一个查询,要求它为我提供特定信息以外的信息。
有没有办法减少 NOT LIKE 的数量并将其全部包含在同一模式中?
PD:我正在使用 Redshift AWS。
SELECT distinct action_url
from event_public
WHERE action_url like '%int/about/%/offices%'
and action_url not LIKE '%russia%'
and action_url not LIKE '%japan%'
and action_url not LIKE '%brazil%'
and action_url not LIKE '%china%'
and action_url not LIKE '%singapore%'
and action_url not LIKE '%nigeria%'
and action_url not LIKE '%algeria%'
and event_action ='Pageview'
是的。您可以使用 REGEXP
SELECT distinct action_url
from event_public
WHERE action_url like '%int/about/%/offices%'
and action_url not REGEXP 'russia|japan|brazil|china|singapore|nigeria|algeria'
and event_action ='Pageview' ;
编辑:对于繁重的匹配,如果 LIKE 可以完成这项工作,请不要使用 REGEXP()。特别是如果可以根据字符串中的第一个字符排除很多行。
您可以使用“~”POSIX 正则表达式运算符。
但是生成的正则表达式会很复杂并且会占用很多 cpu。
参见 redshift docs
您可能更喜欢简单但冗长的点赞列表。
我有一个查询,要求它为我提供特定信息以外的信息。
有没有办法减少 NOT LIKE 的数量并将其全部包含在同一模式中?
PD:我正在使用 Redshift AWS。
SELECT distinct action_url
from event_public
WHERE action_url like '%int/about/%/offices%'
and action_url not LIKE '%russia%'
and action_url not LIKE '%japan%'
and action_url not LIKE '%brazil%'
and action_url not LIKE '%china%'
and action_url not LIKE '%singapore%'
and action_url not LIKE '%nigeria%'
and action_url not LIKE '%algeria%'
and event_action ='Pageview'
是的。您可以使用 REGEXP
SELECT distinct action_url
from event_public
WHERE action_url like '%int/about/%/offices%'
and action_url not REGEXP 'russia|japan|brazil|china|singapore|nigeria|algeria'
and event_action ='Pageview' ;
编辑:对于繁重的匹配,如果 LIKE 可以完成这项工作,请不要使用 REGEXP()。特别是如果可以根据字符串中的第一个字符排除很多行。
您可以使用“~”POSIX 正则表达式运算符。
但是生成的正则表达式会很复杂并且会占用很多 cpu。 参见 redshift docs
您可能更喜欢简单但冗长的点赞列表。