(variable="rank", alias="ranked_bots")
return sqlalchemy.sql.select([
        sqlalchemy.sql.text("(@{v}:=@{v} + 1) AS bot_rank".format(v=variable)),
        bots.c.user_id,
        bots.c.id.label("bot_id"),
        bots.c.mu,
        bots.c.sigma,
        bots.c.score,
        bots.c.games_played,
        bots.c.version_number,
        bots.c.language,
        bots.c.update_time,
        bots.c.compile_status,
    ]).select_from(bots).select_from(sqlalchemy.sql.select([
        sqlalchemy.sql.text("@{}:=0".format(variable))
    ]).alias("rn")).order_by(bots.c.score.desc()).alias(alias)
Builds a query that ranks all bots.

    This is a function in case you need this as a subquery multiple times,
    and would like to avoid reusing the same SQL variable.

    Unfortunately, MySQL does not support SQL variables in views.
Builds a query that ranks all bots.
Builds a query that ranks all bots .
def ranked_bots_query(variable="rank", alias="ranked_bots"):
    """
    Builds a query that ranks all bots.

    This is a function in case you need this as a subquery multiple times,
    and would like to avoid reusing the same SQL variable.

    Unfortunately, MySQL does not support SQL variables in views.
    """
    return sqlalchemy.sql.select([
        sqlalchemy.sql.text("(@{v}:=@{v} + 1) AS bot_rank".format(v=variable)),
        bots.c.user_id,
        bots.c.id.label("bot_id"),
        bots.c.mu,
        bots.c.sigma,
        bots.c.score,
        bots.c.games_played,
        bots.c.version_number,
        bots.c.language,
        bots.c.update_time,
        bots.c.compile_status,
    ]).select_from(bots).select_from(sqlalchemy.sql.select([
        sqlalchemy.sql.text("@{}:=0".format(variable))
    ]).alias("rn")).order_by(bots.c.score.desc()).alias(alias)
def ranked_bots_query ( variable = "rank" , alias = "ranked_bots" ) : return sqlalchemy . sql . select ( [ sqlalchemy . sql . text ( "(@{v}:=@{v} + 1) AS bot_rank" . format ( v = variable ) ) , bots . c . user_id , bots . c . id . label ( "bot_id" ) , bots . c . mu , bots . c . sigma , bots . c . score , bots . c . games_played , bots . c . version_number , bots . c . language , bots . c . update_time , bots . c . compile_status , ] ) . select_from ( bots ) . select_from ( sqlalchemy . sql . select ( [ sqlalchemy . sql . text ( "@{}:=0" . format ( variable ) ) ] ) . alias ( "rn" ) ) . order_by ( bots . c . score . desc ( ) ) . alias ( alias )