题解 | 商品价格排名

商品价格排名

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

全部评论

相关推荐

入职华为的第一步:投递
投递华为技术有限公司等公司10个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
爱睡觉的冰箱哥:你是我今晚见过的最美的牛客女孩
点赞 评论 收藏
分享
09-26 10:17
安徽大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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