select product_id,product_name,category_id,sales_amount,profit_rate from (select product_id,product_name,category_id,sales_amount,round(1-(cost_amount/sales_amount),2) as profit_rate,row_number() over(partition by category_id order by sales_amount desc) as rk from sales_and_profit join product_category using(product_id)) a where profit_rate>0.2 and rk<=3 order by category_id asc,sales_amount desc,product_id asc

京公网安备 11010502036488号