How to retrieve the top N rows for each group
--Solution for SQL Server 2000 and later SELECT ProductID, CategoryID, UnitPrice FROM @Products p1 WHERE ProductID IN (SELECT TOP 3 ProductID FROM @Products p2 WHERE p1.CategoryID = p2.CategoryID ORDER BY UnitPrice DESC) ORDER BY CategoryID, UnitPrice DESC
source : http://gallery.technet.microsoft.com/scriptcenter/How-to-retrieve-the-top-N-248cdc67
Yorumlar