#openGauss #入门 #安装 #数据库 #开源
知识来源:docs-opengauss.osinfra.cn/zh/
子查询表达式
子查询表达式主要有以下几种:
-
EXISTS/NOT EXISTS
EXISTS/NOT EXISTS的语法图请参见图8。
图 8 EXISTS/NOT EXISTS::=
EXISTS的参数是一个任意的SELECT语句,或者说子查询。系统对子查询进行运算以判断它是否返回行。如果它至少返回一行,则EXISTS结果就为"真";如果子查询没有返回任何行, EXISTS的结果是"假"。
这个子查询通常只是运行到能判断它是否可以生成至少一行为止,而不是等到全部结束。
示例:
注:下面查询语句中tpcds是模式名。
openGauss=# SELECT sr_reason_sk,sr_customer_sk FROM tpcds.store_returns WHERE EXISTS (SELECT d_dom FROM tpcds.date_dim WHERE d_dom = store_returns.sr_reason_sk and sr_customer_sk <10); sr_reason_sk | sr_customer_sk --------------+---------------- 13 | 2 22 | 5 17 | 7 25 | 7 3 | 7 31 | 5 7 | 7 14 | 6 20 | 4 5 | 6 10 | 3 1 | 5 15 | 2 4 | 1 26 | 3 (15 rows)
#openGauss #入门 #安装 #数据库 #开源