现有一张成绩表, 主键是用户 id, 如何根据用户 id 查询该用户在表中是否排在前 100 名以及上榜后的名次

现有一张成绩表, 主键是用户 id, 如何根据用户 id 查询该用户在表中是否排在前 100 名以及上榜后的名次
1 wingor2015 Dec 31, 2019 for ind, item in enumerate(Score.objects.order_by('-grade').values('user_id', 'grade')[:100], 1): if item['user_id'] == user_id: return ind else: return -1 |
2 georgema1982 Dec 31, 2019 根据什么来排名? |
3 lenqu Dec 31, 2019 表有么有索引呢?没索引小表直接全部载入,大表切割排序 |