怎么感觉排序这里不太对劲

查询出不同类别商品中,销售金额排名前三且利润率超过 20%的商品信息

https://www.nowcoder.com/practice/3d70132f4c14442cada25fec0198e743

with t1 as(
    select
         pc.product_id
        ,pc.product_name
        ,pc.category_id
        ,sp.sales_amount
        ,sp.cost_amount
        ,row_number()over
        (partition by pc.category_id order by sp.sales_amount  desc) as ar #按销售额排序
        ,round((( sp.sales_amount-sp.cost_amount) 
        / sp.sales_amount),2) as profit_rate
from
    product_category as pc join 
    sales_and_profit as sp on pc.product_id = sp.product_id
order by pc.category_id asc,sp.sales_amount desc,product_id asc

            )
select product_id,product_name,category_id,sales_amount,profit_rate
from t1
where ar<=3 and profit_rate >0.20

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务