本文介绍了MySQL:获取特定行的行号(排名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个users表,该表具有名为money_sent的列.我想按money_sent降序排列此表,然后找出特定用户的排名".

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 out what "rank" a specific user has.

例如,只有111个人比用户12392消费的钱更多,因此他们的排名为112.

For example, only 111 people have spent more money than User 12392, so they would be rank 112.

我该如何查询?

推荐答案

怎么样:

SELECT count(*) FROM users WHERE money_sent < (
    SELECT money_sent FROM users WHERE user = 'joe'
);

这篇关于MySQL:获取特定行的行号(排名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 21:51