How do I rank salespeople by # customers grouped by department (with ties included)?
For example, given this table, I want to create the Rank column on the
SELECT *, (select count(*) from tbl as tbl2 where tbl.customers > tbl2.customers and tbl.dept = tbl2.dept) + 1 as rank from tbl
Just add the dept field to the subquery...