题解 | 商品价格排名

商品价格排名

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

全部评论

相关推荐

下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 10:39
一个证都没&nbsp;我能填什么
程序员小白条:别人有,你为什么没有,还是这个道理,社会就是比较,竞争,淘汰,你要安逸,那么就要做好淘汰的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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