I have a table called bills with the following columns: id, product – product id, product_group – product_group_id, Revenue – revenue in some currency
I would like to get top-2 products from top-5 product groups as of their revenue. Any help is appreciated.
This is i have gone so far:
select t.sum_product_group,
t.sum_product
from (
select bills.product_group,
bills.product,
bills.revenue,
sum(bills.revenue) over (partition by bills.product_group) as sum_product_group,
sum(bills.revenue) over (partition by bills.product) as sum_product,
from bills
) as t
order by t.sum_product_group desc,
t.sum_product desc limit 2