Top rank per group

From Rosetta Code
Revision as of 22:25, 3 December 2008 by 66.120.226.84 (talk)
Task
Top rank per group
You are encouraged to solve this task according to the task description, using any language you may know.

Find the top N rankers per group.

SMEQL

The following SMEQL example returns the top 6 earners in each department based on this table schema:

 table: Employees
 ----------------
 empID
 dept
 empName
 salary 

Source Code:

 srt = orderBy(Employees, (dept, salary), order)
 top = group(srt, [(dept) dept2, max(order) order])
 join(srt, top, a.dept=b.dept2 and b.order - a.order < 6)