I want to get ranking number in Laravel

jatl4f9t6uns :

I want to get ranking number in Laravel.

DB is here.

id Bigint
name string
point BigInt
.....

I want to get ranking number in point column. What should I do?

now code is this.

User::where('id', 1)->first();

if I have these datas.

id name score ...
1    AA      10
2    CD      10
3    ER      40
4    DR      5

I want to get ranking number ex) id 1 => 2 (or3) ex) id 3 => 1

Sehdev :

You can get the rank as below:

User::selectRaw("SELECT id, name, point,  FIND_IN_SET( point, (
                 SELECT GROUP_CONCAT( DISTINCT point ORDER BY point DESC ) FROM 
                user )  
               ) AS rank
                FROM user")

        ->get()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=23591&siteId=1