我有一个 mysql 表,即
st_id | name | email | maths | chemistry | bio | social_study 1 | john |@a.com | 20 | 23 | 10 | 15
我的问题是如何找到最高的科目分数,倒数第二等等
请注意,所有主题字段都有 int(11) 值
最佳答案
将您的数据库分成 3 个表,例如:
学生们:
st_id | name | email
1 | john |@a.com
类(class):
cr_id | name
1 | maths
2 | chemistry
3 | bio
4 | social_studies
学生类(class):
st_id | cr_id | score
1 | 1 | 20
1 | 2 | 23
1 | 3 | 10
1 | 4 | 15
现在您可以:
SELECT s.name, MAX(sc.score) FROM Students INNER JOIN StudentCourses sc ON s.st_id = sc.st_id;
关于php - 如何在mysql表中找到最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5482067/