获取每个类别前两条记录(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
----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