I have been tasked with creating a report that shows sales of our products grouped into buckets of 5 each, DESC. I have a table that has the itemNo and revenue. The final report would be something like:
Top 5 Spreads $695,066
Next 5 Spreads $467,845
Next 5 Spreads $416,946
Next 5 Spreads $361,946
Next 5 Spreads $305,607
Next 5 Spreads $270,567
Bottom Spreads $15,954
My initial thinking was to use row_number() and partition to label the rows in groups of 5 like:
item 1 30,000 1
item 2 29,000 1
item 3 28,000 1
item 4 27,000 1
item 5 26,000 1
item 6 25,000 2
item 7 24,000 2
item 8 23,000 2
item 9 22,000 2
item 10 21,000 2
item 11 20,000 3
item 12 19,000 3
item 13 18,000 3
And then Sum the revenue, grouping by this row_number. But I haven't been able to get it working right. Any other ideas? Maybe I'm on the wrong track. Anyone have other ideas?
Top 5 Spreads $695,066
Next 5 Spreads $467,845
Next 5 Spreads $416,946
Next 5 Spreads $361,946
Next 5 Spreads $305,607
Next 5 Spreads $270,567
Bottom Spreads $15,954
My initial thinking was to use row_number() and partition to label the rows in groups of 5 like:
item 1 30,000 1
item 2 29,000 1
item 3 28,000 1
item 4 27,000 1
item 5 26,000 1
item 6 25,000 2
item 7 24,000 2
item 8 23,000 2
item 9 22,000 2
item 10 21,000 2
item 11 20,000 3
item 12 19,000 3
item 13 18,000 3
And then Sum the revenue, grouping by this row_number. But I haven't been able to get it working right. Any other ideas? Maybe I'm on the wrong track. Anyone have other ideas?