Community Member Profile
- Profile: /members/3843-Jaden.htm
- Comments: 2
- Points: 24
Recent Blog Comments By Jaden
-
Selecting Top X From Each Group
Posted on Feb 20, 2011 at 5:58 PM
@MCouvi Here are two examples of selecting the top n rows, with rows distributed evenly across the groups. These tables are from the MS AdventureWorksLT sample database. SQL Server 2005+ is required, since it uses a CTE and ROW_NUMBER(). This query selects across 3 groups (Count... read more »
-
Selecting Top X From Each Group
Posted on Jul 17, 2009 at 12:37 PM
For SQL Server, ROW_NUMBER() allows for a single scan of the table, which should provider better performance on larger tables, especially when filtering non-indexed columns versus a join/insert method. SELECT id, name, hair, score, ranknum FROM ( SELECT id, name, hair, sc... read more »



