如何在mysql表中找到最大值 [英] how to find the highest value in mysql table
本文介绍了如何在mysql表中找到最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 mysql 表,即<前>st_id |姓名 |电子邮件 |数学 |化学 |生物|社会研究1 |约翰 |@a.com |20 |23 |10 |15
我的问题是我怎样才能找到最高的科目分数,倒数第二等等
请注意,所有主题字段都有 int(11) 值
解决方案
将您的数据库分成 3 个表,例如:
学生:
st_id |姓名 |电子邮件1 |约翰 |@a.com
课程:
cr_id |名称1 |数学2 |化学3 |生物4 |社会研究
学生课程:
st_id |cr_id |分数1 |1 |201 |2 |231 |3 |101 |4 |15
现在你可以:
SELECT s.name, MAX(sc.score) FROM Students s INNER JOIN StudentCourses sc ON s.st_id = sc.st_id;
i have a mysql table i.e
st_id | name | email | maths | chemistry | bio | social_study 1 | john |@a.com | 20 | 23 | 10 | 15
my question is how can i find the highest subject score, the second last and so on
Note that all the subject fields have int(11) values
解决方案
Break your database into 3 tables like:
Students:
st_id | name | email
1 | john |@a.com
Courses:
cr_id | name
1 | maths
2 | chemistry
3 | bio
4 | social_studies
StudentCourses:
st_id | cr_id | score
1 | 1 | 20
1 | 2 | 23
1 | 3 | 10
1 | 4 | 15
Now you can do:
SELECT s.name, MAX(sc.score) FROM Students s INNER JOIN StudentCourses sc ON s.st_id = sc.st_id;
这篇关于如何在mysql表中找到最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文