var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Sorting, Identify position, without returning all results
So lets say I want to find a Rank for a user compared to all other users for a specific variable.
So I can do something like
Select * FROM users order by revenuegenerated
If I want to see where Fred ranks against his peers, I would return all these results, loop through them until I find Fred and using a counter I would get my answer.
Is there a more query friendly way to do this? My database tables are pretty large, and I see no reason to return 700K results when I simply need to know where one user falls in line.
SELECT COUNT(*) + 1 AS rank
FROM users AS t
JOIN users AS x
ON x.revenuegenerated > t.revenuegenerated
WHERE t.username = 'Fred'
Makes perfect sense. Makes me want to knock myself in the head, I should have figured that one out. Thanks for your help and have a good day,