如何在mysql表中找到最高值

sou*_*ode 1 php mysql

我有一个mysql表即

st_id | name | email | maths | chemistry | bio | social_study
1     | john |@a.com | 20    |  23       | 10  |  15


我的问题是如何找到最高的主题分数,倒数第二个等等
注意所有主题字段都有int(11)值

aro*_*oth 5

将数据库分成3个表,如:

学生们:

st_id | name | email  
1     | john |@a.com  
Run Code Online (Sandbox Code Playgroud)

课程:

cr_id | name  
1     | maths  
2     | chemistry  
3     | bio  
4     | social_studies
Run Code Online (Sandbox Code Playgroud)

StudentCourses:

st_id | cr_id | score  
1     | 1     | 20   
1     | 2     | 23   
1     | 3     | 10   
1     | 4     | 15  
Run Code Online (Sandbox Code Playgroud)

现在你可以这样做:

SELECT s.name, MAX(sc.score) FROM Students s INNER JOIN StudentCourses sc ON s.st_id = sc.st_id;