Skip to content

Instantly share code, notes, and snippets.

@Arqentum
Created September 25, 2023 23:10
Show Gist options
  • Select an option

  • Save Arqentum/809f861c26571224ffcba5aeabfaa82a to your computer and use it in GitHub Desktop.

Select an option

Save Arqentum/809f861c26571224ffcba5aeabfaa82a to your computer and use it in GitHub Desktop.
#SQL rollup example
with
tt1 as (
select *
from
(values
(1, 'USD', 'website', 10),
(2, 'USD', 'website', 11),
(3, 'EUR', 'website', 24),
(4, 'EUR', 'domain' , 14),
(5, 'EUR', 'domain' , 74),
(6, 'GBP', 'domain', 105)
) x (id, tcy, product, amount)
)
select
coalesce(tcy,'total'),
coalesce(product,'total'),
sum(tt1.amount) sum_amount
from
tt1
GROUP BY rollup (product, (tcy, product))
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment