Top rank per group

From Rosetta Code
Revision as of 22:08, 3 December 2008 by 66.120.226.84 (talk) (New page: 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 ---------------...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)