I have a users
table that has a column called money_sent
. I want to order this table by money_sent
in descending order, and then find
How about:
SELECT count(*) FROM users WHERE money_sent < (
SELECT money_sent FROM users WHERE user = 'joe'
);
If you also want to get the user's row along with that user's rank, you can use something like this:
SELECT u1.*, COUNT(u2.user)
FROM users u1
LEFT OUTER JOIN users as u2 ON (u1.money_sent < u2.money_sent)
GROUP BY u1.user;
SELECT Row,user, money_sent
FROM (SELECT @row := @row + 1 AS Row, user, money_sent
FROM table1 order by money_sent desc)
As derived1