Skip to content

Instantly share code, notes, and snippets.

@steve-ng
Last active March 28, 2020 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steve-ng/dcaed9eaae8f208901adfb9a19128f5d to your computer and use it in GitHub Desktop.
Save steve-ng/dcaed9eaae8f208901adfb9a19128f5d to your computer and use it in GitHub Desktop.
medium post
/* Assume the table is called order on Athena */
SELECT
"item category",
reduce(kv1['Asia Pacific'], 0.0, (s, x) -> s + x, s-> s) AS "Asia Pacific",
reduce(kv1['North America'], 0.0, (s, x) -> s + x, s-> s) AS "North America"
FROM (
SELECT
"item category",
multimap_agg("region", amount) kv1
FROM order
GROUP BY "item category"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment