获取每个类别前两条记录(northwind数据库)

 --CategoryID 分类ID 
 ----ProductID 产品ID
 --Products 产品表
SELECT * FROM Products a WHERE ProductID in
(SELECT top 2 ProductID FROM  Products WHERE CategoryID=a.CategoryID GROUP BY CategoryID,ProductID  )
ORDER BY CategoryID
原文地址:https://www.cnblogs.com/gossip/p/1730301.html