一。select * from(
select ID,ShopClient_ID,Name,Icon,HitCount,Class1_ID,row_number() over(partition by Class1_ID order by HitCount desc)
as rowindex from tab_Goods)a
where rowindex<=5
二。SELECT * FROM tab_Goods a
WHERE (SELECT count(*) FROM tab_Goods b WHERE b.Class1_ID=a.Class1_ID AND b.ID>a.ID)<5
ORDER BY Class1_ID desc
每个分类取5条, Sql解决方法,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/Vlaner/p/3809943.html