I'd like to use postgresql window functions like rank()
and dense_rank
in some queries in need to do in Django. I have it working in raw SQL but I'm not sure how to do this in the ORM.
Simplified it looks like this:
SELECT
id,
user_id,
score,
RANK() OVER(ORDER BY score DESC) AS rank
FROM
game_score
WHERE
...
How would you do this in the ORM?
At some point I might need to add partitioning too :|
(we're using Django 1.9 on Python 3 and already depend on django.contrib.postgres features)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…