Athena sql 查询以查找不包含值的项目
Athena sql query to find items not containing a value
我在存储桶中有一个 table,我正在使用 Athena 获取所需的数据
我的 table 看起来像
resourceid appname
i-1 A-1
i-1 A-2
i-1 A-3
i-2 A-3
i-2 A-2
我需要找到所有没有找到A-1的资源
结果应该给我 i-2。如何写成sql
您可以使用聚合将具有相同 resourceid
的所有行分组在一起,然后过滤掉 appname
'A-1'
未出现的行组:
select resourceid
from mytable
group by resourceid
having max(case when appname = 'A-1' then 1 else 0 end) = 0
您可以使用 not exists
。这是 demo.
select
distinct resourceid
from myTable m1
where not exists (
select
resourceid
from myTable m2
where m1.resourceid = m2.resourceid
and appname = 'A-1'
)
我在存储桶中有一个 table,我正在使用 Athena 获取所需的数据 我的 table 看起来像
resourceid appname
i-1 A-1
i-1 A-2
i-1 A-3
i-2 A-3
i-2 A-2
我需要找到所有没有找到A-1的资源 结果应该给我 i-2。如何写成sql
您可以使用聚合将具有相同 resourceid
的所有行分组在一起,然后过滤掉 appname
'A-1'
未出现的行组:
select resourceid
from mytable
group by resourceid
having max(case when appname = 'A-1' then 1 else 0 end) = 0
您可以使用 not exists
。这是 demo.
select
distinct resourceid
from myTable m1
where not exists (
select
resourceid
from myTable m2
where m1.resourceid = m2.resourceid
and appname = 'A-1'
)