Top rank per group: Difference between revisions

From Rosetta Code
Content added Content deleted
(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 ---------------...)
 
No edit summary
Line 1: Line 1:
Find the top N rankers per group.
Find the top N rankers per group.


==SMEQL==
=={{header|SMEQL}}==


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

Revision as of 22:10, 3 December 2008

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)