简体   繁体   English

根据另一列的值排除记录

[英]Excluding Records Based on Another Column's Value

I'm working in Redshift and have two columns from an Adobe Data feed:我在 Redshift 工作,并且有两列来自 Adob​​e 数据提要:

post_evar22 and post_page_url. post_evar22 和 post_page_url。

Each post_evar22 has multiple post_page_url values as they are all the pages that the ID visited.每个 post_evar22 都有多个 post_page_url 值,因为它们是 ID 访问的所有页面。 (It's basically a visitor ID and all the pages they visited) (它基本上是一个访问者 ID 和他们访问的所有页面)

I want to write a query where I can list distinct post_evar22 values that have never been associated with a post_page_url that contains '%thank%' or '%confirm%'.我想编写一个查询,我可以在其中列出从未与包含“%thank%”或“%confirm%”的 post_page_url 关联的不同 post_evar22 值。

In the dataset below, ID1 would be completely omitted from the query results bceause it was associated with a thank-you page and a confirmation page.在下面的数据集中,ID1 将从查询结果中完全省略,因为它与感谢页面和确认页面相关联。

在此处输入图像描述

This is a case for NOT EXISTS:这是不存在的情况:

select distinct post_evar22
from table t1
where not exists (
    select 1
    from table t2
    where t2.post_evar22 = t1.post_evar22
    and (t2.post_page_url like '%thank%' or t2.post_page_url like '%confirm%')
)

Or MINUS if your dbms supports it:如果您的 dbms 支持,则为 MINUS:

select post_evar22 from table
minus
select post_evar22 from table where (post_page_url like '%thank%' or post_page_url like '%confirm%')

Seems fairly straight forward.似乎相当直截了当。 Am I missing something?我错过了什么吗?

SELECT DISTINCT post_evar22
FROM table 
WHERE post_page_url NOT LIKE '%thank%' 
    AND post_page_url NOT LIKE'%confirm%

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM