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