i'am trying to get the users rank so i can display their rank in a div.. i.e you are 30 out of 400 users at getting sales.
So far i ve managed to get the order of the users but thats it: i count the date_mades as sales made to get the totals.
SELECT usr_id, count(date_made) as dater, @curRank := @curRank + 1 AS rank FROM firsts
group BY usr_id order by dater desc
gives me :
usr_id dater rank
1 20 NULL
16 3 NULL
3 2 NULL
5 1 NULL
9 1 NULL
22 1 NULL
25 1 NULL
i found this answer (Attached snippet) but i just get red crosses all over the statement when i try and run it: does anyone else get errors just pasting this into their phpmyadmin? is it a parser problem or syntax?
SELECT pid, name, age, rank FROM
(SELECT pid, name, age,
@curRank := IF(@prevRank = age, @curRank, @incRank) AS rank,
@incRank := @incRank + 1,
@prevRank := age
FROM players p, (
SELECT @curRank :=0, @prevRank := NULL, @incRank := 1
) r
ORDER BY age) s