SPARK SQL:必须聚合相关标量子查询

问题描述 投票:0回答:1

我收到错误,因为“相关标量子查询必须聚合才能最多返回一行。”

Nvl(select addr_cntry_cd from (add_cntry_cd, risk, row_number() over partition by add_cntry_cd order by risk desc) as rn from country where derived_addr in (orig, benef, send) ) sub where sub.rn = 1) , 'Not Found') Orig_country 

在这里,如果我执行 max(addr_cntry_cd) 只获取 1 行,则会给出错误“此位置过滤器中不允许访问外部查询列”

如有任何帮助,我们将不胜感激🙏

在运行 ht 代码时使用 %sql 在 Spark sql 中的 azure databricks 中运行它。

期望在 adb 中运行时不会出现错误。

sql apache-spark pyspark adb
1个回答
0
投票

虽然您确实需要输入格式化的完整 SQL 语句才能获得准确的帮助,但错误消息非常清晰。 您可以使用 max/min/first/last 等从子查询中选择一行(我假设为“sub”)。

或者,如果您确实想要多行,那么您必须使用完整的联接。

© www.soinside.com 2019 - 2024. All rights reserved.