Skip to content

Instantly share code, notes, and snippets.

@darkjh
Last active August 11, 2021 13:06
Show Gist options
  • Save darkjh/72710709644766a543efd0595fb095d4 to your computer and use it in GitHub Desktop.
Save darkjh/72710709644766a543efd0595fb095d4 to your computer and use it in GitHub Desktop.
WITH aggregated_metrics AS (
SELECT arbitrary(pop) AS pop, arbitrary(idx) AS idx, SUM(m) as m
FROM (
VALUES
(1, ARRAY[2, 5, 7]),
(2, ARRAY[45, 8, 7]),
(1, ARRAY[100, 0, 3])
) AS log (pop, metric)
CROSS JOIN UNNEST(metric) WITH ORDINALITY AS t (m, idx)
GROUP BY pop, idx
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment