within group sorts in mysql
问题 I have a panel data set: that is, times , ids , and values . I would like to do a ranking based on value for each date. I can achieve the sort very simply by running: select * from tbl order by date, value The issue I have is once the table is sorted in this way, how do I retrieve the row number of each group (that is, for each date I would like there to be a column called ranking that goes from 1 to N). Example: Input: Date, ID, Value d1, id1, 2 d1, id2, 1 d2, id1, 10 d2, id2, 11 Output: