with t1 as ( select product_id, customer_age_group from ( select rank() over ( partition by product_id order by sa desc,customer_age_group ) as r, product_id, customer_age_group from ( select product_id, sum(quantity) as sa, case when customer_age between 1 and 10 then '1-10' when customer_age betwe...