How to remove the duplicate data from the ranking query results?

there is a user ranking table, which needs to be sorted by score and output. If there is a duplicate user, take the highest score of that user
now I write

DB::select("SELECT nickname, id, fraction, FIND_IN_SET( fraction, (    
                    SELECT GROUP_CONCAT( fraction
                    ORDER BY fraction DESC ) 
                    FROM fan_rankings WHERE test_id=$test_id)
                    ) AS rank
                    FROM fan_rankings
                    WHERE test_id = $test_id AND user_id = $user->id ORDER BY fraction DESC");

I added a GROUP BY (user_id before ORDER BY), but if there is an error, please tell me what to do
and how to write it in ORM. I feel it"s a bit complicated to write in native
my own version of laravel5.4
Please don"t hesitate to give me your advice

.
Jun.24,2021

DB::select("SELECT distinct nickname, id, fraction, FIND_IN_SET( fraction, (    
                    SELECT GROUP_CONCAT( fraction
                    ORDER BY fraction DESC ) 
                    FROM fan_rankings WHERE test_id=$test_id)
                    ) AS rank
                    FROM fan_rankings
                    WHERE test_id = $test_id AND user_id = $user->id ORDER BY fraction DESC");

try adding a distinct


do it with redis! Mysql is not suitable for real-time ranking at all


FanRanking::query()->groupBy('user_id')->orderByDesc('fraction')->limit(100)->get(['user_id', \DB::raw('max(fraction) as fraction')])

the answer from a big guy in the laravel community looks concise and useful!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e57be7-447ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e57be7-447ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?