简体   繁体   English

BigQuery。 标量子查询产生了多个元素

[英]BigQuery. Scalar subquery produced more than one element

Here is a query which results in this error: Query Failed Error: Scalar subquery produced more than one element 这是导致此错误的查询:查询失败错误:标量子查询产生多个元素

select date
       ,isdepositor
       ,category 
       ,(select distinct dd from unnest(d.subcategory) dd) subcategory
       ,dau
from(
       select date
       ,isdepositor
       ,'Level' as Category
       ,array(select 'Daily' union all select 'Weekly' union all select 'Monthly') subcategory
       , dau 
       from DWH.vT_DAU
) d

DWH.vT_DAU is a view, where DAU is calculated for each date and boolean field 'isdepositor'. DWH.vT_DAU是一个视图,其中为每个日期和布尔字段“ isdepositor”计算DAU。

I need to create custom fields 'Category' and 'Subcategory' where the same for each 'date' and 'isdepositor' DAU will be displayed. 我需要创建自定义字段“ Category”和“ Subcategory”,其中每个“日期”和“ isdepositor” DAU都将显示相同的字段。

I found some similar question regarding this bigquery error here, however, any solution didn't work for me. 我在这里发现了与此bigquery错误类似的问题,但是,任何解决方案都不适用于我。

Any help would be appreciated. 任何帮助,将不胜感激。 Thank you! 谢谢!

I need to create custom fields 'Category' and 'Subcategory' where the same for each 'date' and 'isdepositor' DAU will be displayed. 我需要创建自定义字段“ Category”和“ Subcategory”,其中每个“日期”和“ isdepositor” DAU都将显示相同的字段。

Below does exactly this 下面正是这样

#standardSQL
SELECT 
  date
  ,isdepositor
  ,'Level' AS Category
  ,subcategory
  , dau 
FROM `DWH.vT_DAU`
CROSS JOIN 
  (SELECT 'Daily' subcategory UNION ALL SELECT 'Weekly' UNION ALL SELECT 'Monthly')

above is equivalent to below - which is most likely what you ended up (based on your comment) 上方等于下方-这很可能是您最终得到的结果(根据您的评论)

#standardSQL
SELECT 
  date
  ,isdepositor
  ,'Level' AS Category
  ,subcategory
  , dau 
FROM `DWH.vT_DAU`
, UNNEST(['Daily', 'Weekly', 'Monthly']) subcategory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM