Welcome Guest, Not a member yet? Register   Sign In
Calculate position based on a value
#6

(This post was last modified: 12-17-2015, 06:31 AM by davicotico. Edit Reason: fix )

(12-17-2015, 12:22 AM)Violette Wrote: Thank you but I had already made the correction.
I have trouble writing my fuction.
Someone an idea to move me please

With this fields: from_user_id, total_stats

You can order by total_stats and get the rank position without update another table:

Code:
SELECT from_user_id, total_stats, position FROM
    (
    SELECT t.from_user_id, total_stats,
        @rownum := @rownum + 1 AS position
    FROM score t, (SELECT @rownum := 0) r
    ORDER BY total_stats DESC
    ) as table_position

And for a single user too:

Code:
SELECT from_user_id, total_stats, position FROM
    (
    SELECT t.from_user_id, total_stats,
        @rownum := @rownum + 1 AS position
    FROM score t, (SELECT @rownum := 0) r
    ORDER BY total_stats DESC
    ) as table_position
WHERE from_user_id = 25032

Reply


Messages In This Thread
Calculate position based on a value - by Violette - 12-14-2015, 08:09 AM
RE: Calculate position based on a value - by davicotico - 12-17-2015, 06:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB