I'm not a ORACLE user but I've found an interesting article about it:
Oracle SQL GROUP BY – The Complete Guide
Scrolling down till the GROUPING Function you'll find and example on how use GROUP BY with ROLLUP:
Quoted from the article
There are several SQL functions related to grouping that can help you
identify and work with groups.
Earlier in our examples, we noticed that subtotals had values of NULL
for the columns that weren’t being considered in the group.
How can we tell which values are subtotals and which values are NULL
because of the underlying data?
This is what the GROUPING function can help with.
The GROUPING function takes a single column as a parameter. The output
is either 1 or 0:
It returns 1 if the column is being used as part of a subtotal and is
showing NULL. It returns 0 if the underlying value is NULL or any
You can also order by these columns, to have the subtotals at the
start or the end, instead of in the middle of the results.
According to this you could use the next syntax to produce the expected result:
SUM(Amount) as AmoutOfMone
GROUP BY ROLLUP (Year, Month)
Due this question has a previous question here, I've used my fiddle to add this new information and it works properly.
/* aggregated sales by year-month */
T.CALENDAR_YEAR AS Year,
T.CALENDAR_MONTH_DESC AS Month,
SUM(S.AMOUNT_SOLD) AS AmountOfMoney
ON T.TIME_ID = S.TIME_ID
WHERE S.PROD_ID = 1
GROUP BY ROLLUP (T.CALENDAR_YEAR, T.CALENDAR_MONTH_DESC)
ORDER BY GROUPING (T.CALENDAR_YEAR) DESC,
GROUPING (T.CALENDAR_MONTH_DESC) DESC,
YEAR | MONTH | AMOUNTOFMONEY
---: | ----: | ------------:
null | null | 450
2018 | null | 450
2018 | 1 | 100
2018 | 2 | 200
2018 | 3 | 150