View a markdown version of this page

EXISTS 条件 - Amazon Redshift

2026 年 6 月 30 日之后,Amazon Redshift 不再支持使用 Python UDF。我们将分阶段开始执行。有关 Python 生命周期终止和迁移选项详情的更多信息,请参阅 2025 年 6 月 30 日发布的博客文章

EXISTS 条件

EXISTS 条件测试子查询中是否存在行,并在子查询返回至少一个行时返回 true。如果指定 NOT,此条件将在子查询未返回任何行时返回 true。

语法

[ NOT ] EXISTS (table_subquery)

参数

EXISTS

table_subquery 返回至少一行时,为 true。

NOT EXISTS

table_subquery 未返回任何行时,为 true。

table_subquery

计算结果为包含一个或多个列和一个或多个行的表的子查询。

示例

此示例针对具有任何类型的销售的日期返回所有日期标识符,一次返回一个日期:

select dateid from date where exists ( select 1 from sales where date.dateid = sales.dateid ) order by dateid; dateid -------- 1827 1828 1829 ...