Created
October 15, 2025 12:23
-
-
Save rmorenobello/c0fdf8d3a7b5193eea9330e3687818eb to your computer and use it in GitHub Desktop.
Oracle - GROUP BY with rollup with titles
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
| SELECT | |
| CASE | |
| WHEN GROUPING(REGION) = 1 THEN 'TOTAL GENERAL' | |
| ELSE REGION | |
| END AS REGION, | |
| CASE | |
| WHEN GROUPING(PRODUCTO) = 1 THEN 'TOTAL REGIÓN' | |
| ELSE PRODUCTO | |
| END AS PRODUCTO, | |
| SUM(IMPORTE) AS TOTAL_VENTAS | |
| FROM VENTAS | |
| GROUP BY ROLLUP(REGION, PRODUCTO) | |
| ORDER BY REGION, PRODUCTO; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment