Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL SCORE RANKING

Tags:

mysql

I'm working with score ranking on my app for all user score. My problem is I don't know how to return one row for each stud_num.

My query:

SELECT * FROM score WHERE assess_type = 'professional' ORDER BY total_score DESC.

Result: RESULT

As you can see I have 3 stud_num and I only want one row per stud_num and the highest score of it.

like image 479
Majikero Gallardo Avatar asked Apr 19 '26 02:04

Majikero Gallardo


1 Answers

You can use correlated query like this:

SELECT * FROM score t
WHERE t.assess_type = 'professional' 
      AND t.total_score = (select max(s.total_score) 
                           from score s
                           where t.stud_num = s.stud_num)
group by stud_num
like image 131
sagi Avatar answered Apr 22 '26 01:04

sagi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!