题解 | 商品价格排名

商品价格排名

https://www.nowcoder.com/practice/119f5b8cfe5b45779a3e1b3f4d83b341

#1.先求出每个商品类型的价格的前2名的商品。
#2.在将上述的商品在进行个排序,取前三。
with tiaojian as (
select
product_id,
product_name,
type,
price,
dense_rank()over(partition by type order by price desc) as pf
from product_info
)

select 
t.product_id,
t.product_name,
t.type,
t.price
from(
select 
product_id,
product_name,
type,
price,
row_number()over(order by price desc,product_name asc) as pdiff
from tiaojian
where
pf<=2
) as t 
where
t.pdiff<=3

全部评论

相关推荐

用微笑面对困难:只要你保证项目和获奖都是真的就行尤其是“对战,总负责人”啊这些套职,基本上队员,打杂的都这么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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