How to get Not Exists Record List from the Given List in Presto with ANSI SQL

问题描述 投票:0回答:1

如何从给定的输入条件中获取不存在的记录列表?

如果我们使用 Not IN 运算符,它将从表中得出所有不匹配的记录。但是我想从给定的输入条件中获取不匹配的记录。

我知道这个答案适用于 oracle 数据库,但这是 Presto 独有的。有人可以帮忙吗?

select i.column_value as country_code     
from table(SYS.DBMS_DEBUG_VC2COLL('AU', 'IN', 'ZA', 'DK', 'CH', 'NL')) i   
where not exists 
(select null                                
from country c                              
where c.country_code = i.column_value)
sql presto dbt
1个回答
0
投票

Oracle

SYS.DBMS_DEBUG_VC2COLL
函数用于将逗号分隔的列表转换为行列表,就像从表中进行选择一样。 Presto 中的“未嵌套”数组应该替代它,例如:

SELECT t.country_code
FROM UNNEST(ARRAY['AU', 'IN', 'ZA', 'DK', 'CH', 'NL']) AS t(country_code)
WHERE NOT EXISTS (
    SELECT 1
    FROM country c
    WHERE c.country_code = t.country_code
)
© www.soinside.com 2019 - 2024. All rights reserved.