

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 範例：在 Redshift Spectrum 中執行相互關聯子查詢
<a name="c_performing-correlated-subqueries-spectrum"></a>

本主題說明如何在 Redshift Spectrum 中執行相互關聯子查詢。相互關聯子查詢是使用外部查詢值的查詢。

您可以在 Redshift Spectrum 中執行相互關聯子查詢。`$spectrum_oid` 虛擬資料欄提供使用 Redshift Spectrum 執行相關查詢的能力。若要執行相互關聯子查詢，虛擬資料欄 `$spectrum_oid` 必須啟用，但不會出現在 SQL 陳述式中。如需詳細資訊，請參閱[虛擬資料欄](c-spectrum-external-tables.md#c-spectrum-external-tables-pseudocolumns)。

若要為此範​​例建立外部結構描述和外部資料表，請參閱[開始使用 Amazon Redshift Spectrum](c-getting-started-using-spectrum.md)。

以下是 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
```