根据BigQuery SQL编辑器,此查询“有效”。但是,当它运行时,会产生错误:标量子查询产生了多个元素
输入:
SELECT
(Select
pcr.repdte
from
usa_fdic_call_reports_1992.All_Reports_19921231_
Performance_and_Condition_Ratios as PCR) as Quarter,
(SELECT
Round(PCR.lnlsdepr)
FROM
usa_fdic_call_reports_1992.All_Reports_19921231_Performance_
and_Condition_Ratios as PCR) as NetLoansAndLeasesToDeposits,
(SELECT LD.IDdepsam
FROM usa_fdic_call_reports_1992.All_Reports_19921231_
Deposits_Based_on_the_dollar250_000_Reporting_Threshold
AS LD) as DepositAccountsWithMoreThan250k
输出 标量子查询产生了多个元素
查询独立运行时的输出如下:
SELECT
PCR.repdte as quarter
FROM
usa_fdic_call_reports_1992.All_Reports_19921231_
Performance_and_Condition_Ratios as PCR
SELECT
Round(PCR.lnlsdepr) as NetLoansAndLeasesToDeposits
FROM
usa_fdic_call_reports_1992.All_Reports_19921231_
Performance_and_Condition_Ratios as PCR
SELECT LD.IDdepsam as DepositAccountsWithMoreThan250k
FROM
usa_fdic_call_reports_1992.All_Reports_
19921231_Deposits_Based_on_the_dollar250_000_
Reporting_Threshold AS LD
答案 0 :(得分:1)
标量子查询所产生的内容不能超过单行。您要显示的标量子查询显示单列和多行。顾名思义,那是行不通的。
答案 1 :(得分:0)
我不使用子查询,而是使用JOIN解决了问题
SELECT
pcr.cert as cert,
pcr.name as NameOfBank,
pcr.repdte as Quarter,
Round(PCR.lnlsdepr) as NetLoansAndLeasesToDeposits,
LD.IDdepsam as DepositAccountsWithMoreThan250k
FROM
usa_fdic_call_reports_1992.All_Reports_19921231_Performance
_and_Condition_Ratios as PCR
JOIN
usa_fdic_call_reports_1992.All_Reports_19921231_Deposits_Based_
on_the_dollar250_000_Reporting_Threshold AS LD
ON PCR.cert = LD.cert
答案 2 :(得分:0)
要修复,请使用ARRAY
。
例如,此查询有效:
SELECT 1 x, (SELECT y FROM UNNEST(SPLIT("1")) y) y
但是这个会给你陈述的错误:
SELECT 1 x, (SELECT y FROM UNNEST(SPLIT("1,2")) y) y
"Scalar subquery produced more than one element"
我可以用ARRAY()
进行修复,这将产生嵌套的重复结果:
SELECT 1 x, ARRAY(SELECT y FROM UNNEST(SPLIT("1,2")) y) y
或者确保仅使用LIMIT
发出一行:
SELECT 1 x, (SELECT y FROM UNNEST(SPLIT("1,2")) y LIMIT 1) y