Rank only summary rows from group by rollup
I would like to rank only the total rows generated by a group by rollup, but not rank the rows within each group by bucket. Furthermore, I'd like to order by rank in descending order and include the unranked rows within each group.
My query looks something like this:
select customer, month, sum (sell)
from sales
group by rollup (customer, month)
order by customer, month desc nulls first
The results look like:
customer month sum(sell)
<summary rowA> 1,200
custA JAN 100
custA FEB 100
custA MAR 100
.
.
custA DEC 100
<summary rowB> 600
custB JAN 50
custB FEB 50
custB MAR 50
.
.
custB DEC 50
What I would like to do is:
select dense_rank() over (order by sum(sell) desc <rollup rows only>) as rank,
customer, month, sum (sell)
from sales
group by rollup (customer, month)
order by <summary row rank desc> customer, month desc nulls first
The results would look like:
rank customer month sum(sell)
1 <summary rowA> 1,200
custA JAN 100
custA FEB 100
custA MAR 100
.
.
custA DEC 100
2 <summary rowB> 600
custB JAN 50
custB FEB 50
custB MAR 50
.
.
custB DEC 50
Any advice?
Thank you