Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

sql server select top 2 of each group

SELECT * FROM 
(
SELECT column1, 
column2,
cloumn3, 
row_number() over (PARTITION BY ColumnToGroupBy ORDER BY ColumnToOrderBy DESC) AS TempColumnName
FROM cities
) AS TempTableName
WHERE TempTableName <= 2
Source by www.silota.com #
 
PREVIOUS NEXT
Tagged: #sql #server #select #top #group
ADD COMMENT
Topic
Name
1+9 =