简体   繁体   English

Bigquery 中重复数字列(数组)的总和

[英]Sum of repeated numeric columns (array) in Bigquery

How can I get the sum of a repeated numeric column (array) in BigQuery?如何获取 BigQuery 中重复数字列(数组)的总和?

For example, from the following array:例如,来自以下数组:

SELECT [4, 5, 9] as repeated_numeric
UNION ALL SELECT [2,3];
Row repeated_numeric重复数字
1 1 [4, 5, 9] [4、5、9]
2 2 [2,3] [2,3]

I am looking for this result:我正在寻找这个结果:

| | Row |行 | sum |总和 | |:---: |:---: | |:---: |:---: | | | 1 | 1 | 18 | 18 | | | 2 | 2 | 5 | 5 | The length of my arrays is not fixed.我的 arrays 的长度不固定。

Consider below simple approach考虑以下简单的方法

select repeated_numeric, 
  (select sum(num) from t.repeated_numeric num) total
from your_table t           

if applied to sample data in your question - output is如果应用于您问题中的示例数据 - output 是

在此处输入图像描述

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

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