本文主要是介绍分组排列,每组前几名sql,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
create table `shop` (
`id` int (10) PRIMARY KEY,
`shop_name` varchar (100),
`item_name` varchar (100),
`price` int (10)
);
每个shop 中价格最高的前N 条数据
select * from shop a where N > (select count(*) from shop b where b.shop_name = a.shop_name and b.price<a.price) order by a.shop_name,a.price desc;
每个shop 中价格最第的前N 条数据
select * from shop a where N > (select count(*) from shop b where b.shop_name = a.shop_name and b.price>a.price) order by a.shop_name,a.price desc;
这篇关于分组排列,每组前几名sql的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!