Created
September 25, 2023 23:10
-
-
Save Arqentum/809f861c26571224ffcba5aeabfaa82a to your computer and use it in GitHub Desktop.
#SQL rollup example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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