0

How can I get the sum of a repeated numeric column (array) in BigQuery ?

For example, from the following array:

SELECT [4, 5, 9] as repeated_numeric
UNION ALL SELECT [2,3];
Row repeated_numeric
1 [4, 5, 9]
2 [2,3]

I am looking for this result:

Row sum
1 18
2 5

The length of my arrays is not fixed.

1 Answer 1

1

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.