示例:在 Redshift Spectrum 中执行相关的子查询 - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

示例:在 Redshift Spectrum 中执行相关的子查询

您可以在 Redshift Spectrum 中执行相关的子查询。$spectrum_oid 伪列提供了使用 Redshift Spectrum 执行相关查询的功能。要执行关联的子查询,必须启用伪列 $spectrum_oid,但它不会显示在 SQL 语句中。有关更多信息,请参阅 Pseudocolumns

要为此示例创建外部架构和外部表,请参阅Amazon Redshift Spectrum 入门

以下是 Redshift Spectrum 中相关子查询的示例。

select * from myspectrum_schema.sales s where exists ( select * from myspectrum_schema.listing l where l.listid = s.listid ) order by salesid limit 5;
salesid listid sellerid buyerid eventid dateid qtysold pricepaid commission saletime 1 1 36861 21191 7872 1875 4 728 109.2 2008-02-18 02:36:48 2 4 8117 11498 4337 1983 2 76 11.4 2008-06-06 05:00:16 3 5 1616 17433 8647 1983 2 350 52.5 2008-06-06 08:26:17 4 5 1616 19715 8647 1986 1 175 26.25 2008-06-09 08:38:52 5 6 47402 14115 8240 2069 2 154 23.1 2008-08-31 09:17:02