Use Access SQL to do a grouped ranking

后端 未结 6 704
悲哀的现实
悲哀的现实 2020-11-29 12:26

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

6条回答
  •  -上瘾入骨i
    2020-11-29 12:47

    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...

提交回复
热议问题