sql - MS access - ranking equal values incrementally -
is possible rank records in access duplicate values given incremental rank (like row_number function in sql server)?
i want rank following set of records:
id type score 1 team1 4 1 team2 2 1 team3 1 1 team4 1
the query have:
select * tbl tbl1 tbl1.id in ( select top 3 type tbl tbl2 tbl2.id = tbl1.id order tbl2.score )
ranks them follows
id type score rank 1 team1 4 1 1 team2 2 2 1 team3 1 3 1 teams 1 3
i need rank them this:
id type score rank 1 team1 4 1 1 team2 2 2 1 team3 1 3 1 team4 1 4
can done in access?
edit: the rankings need grouped
bigger sample of data , want represent in derived column, ids have more records others:
id type score rank 1 team1 4 1 1 team2 2 2 1 team3 1 3 1 team4 1 4 2 team1 2 1 2 team3 2 2 2 team2 1 3 4 team1 4 1 4 team3 4 2 4 team5 3 3 4 team4 1 4 4 team2 1 5
eventually want select top 3 rows each id
consider solution difference equation on 2 conditional aggregate count subqueries. tiebreaker uses order of alphabetical order type
:
select tbl.id, tbl.type, tbl.score, (select count(*) tbl sub sub.id = tbl.id , sub.score >= tbl.score ) - (select count(*) - 1 tbl sub sub.id = tbl.id , sub.type >= tbl.type , sub.score = tbl.score) [rank] tbl order id, score desc, type;
Comments
Post a Comment