I figured it out. I had to run cursor.execute for the SET and the
SELECT line and it managed to remember the @row being 0 between them.
Though it would be nice if a django solution exists.

Regardless,
MikeL

On May 4, 10:15 am, MikeL <[email protected]> wrote:
> I'm trying to make a query which lists the top 5 rated users along
> with the rating (and rank) of the current user. The top 5 was easy,
> but I'm having a problem getting the rank of the current user. I know
> the sql needed to calculate the rank, but it requires a variable.
>
> SET @row=0;
> SELECT rank from
> (
>         SELECT @row:=...@row+1 as rank, user_id, variant_id
>                 FROM a_table
>                 WHERE variant_id=0
>                 ORDER BY rating DESC
> ) AS A
>         WHERE user_id=0;
>
> I've tried cursor.execute and cursor.fetchone(), but I don't any
> return. I removed the first line and did get a return, only it was
> NULL. Is there anyway to do this with Django's models or a way to get
> the sql above to work?
>
> TIA,
> MikeL
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to