如何使用ANSI SQL从给定列表中获取Presto中不存在的记录列表。

huangapple go评论66阅读模式
英文:

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

问题

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

如果我们使用“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)
英文:

How to get the list of Not Exists Record List from the Given Input Condition?

If we are using Not IN Operator, it will result all the not matching records from the table. But I want to get the not matching record from the Given Input Condition.

如何使用ANSI SQL从给定列表中获取Presto中不存在的记录列表。

I know this answer is there for oracle database but this is exclusively needed for Presto. Can someone help on this?

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)

答案1

得分: 1

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
)
英文:

The Oracle SYS.DBMS_DEBUG_VC2COLL function is used to transform a comma-separated list into a list of rows, just like a select from a table.
An "unnested" array in Presto should substitute for this, e.g.:

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
)

huangapple
  • 本文由 发表于 2023年3月8日 17:34:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671374.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定