I'm trying to calculate the rank of a particular (unique) row id by using a
subquery:
I first calculate the total ranking for a table, Game (using 1.4.23):
sq = (
session.query(
Game.id,
Game.score,
func.rank().over(order_by=Game.score.desc()).label("rank"),
)
.filter(Game.complete == True)
.subquery()
)
Then filter by the row ID I want (gameid):
gamerank = (
session.query(
sq.c.id, sq.c.score, sq.c.rank
)
.filter(sq.c.id == gameid)
.limit(1)
.one()
)
Game.score is a Float column. Is this the most efficient way to do this, or
am I over-complicating it?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/e0373046-8379-499f-b584-37eb032636b9n%40googlegroups.com.