#查询出不同类别商品中,销售金额排名前三且利润率超过 20%的商品信息, #包含的字段:商品 ID、商品名称、所属类别 ID、销售金额、利润率((销售金额 - 成本金额)/ 销售金额)。 #结果先按照类别 ID 升序排列,再按照销售金额降序排列,如果金额一致按照产品ID升序排列 ### 不知道是题目出错还是用例答案出错,ranking <= 3不通过,实际上提取的是销售金额排名前四的商品 select product_id,product_name,category_id,sales_amount,profit_rate from( select a.product_id,product_name,category_id,sum(sales_amount) as sales_amount,round((sales_amount-cost_amount)/sales_amount,2) as profit_rate,dense_rank()over(order by sales_amount desc) as ranking from product_category as a left join sales_and_profit as b on a.product_id = b.product_id group by a.product_id,product_name,category_id ) as temp1 where profit_rate >= 0.2 and ranking <= 4 order by category_id,sales_amount desc,product_id