这是我的学生表 stud 表
rollno | name |
---|---|
1 | A |
2 | B |
3 | C |
4 | B |
5 | D |
6 | C |
这是我的成绩表 marks 表
rollno | mar | eng | maths | phy | chem |
---|---|---|---|---|---|
1 | 40 | 45 | 38 | 50 | 50 |
2 | 28 | 50 | 45 | 41 | 38 |
3 | 41 | 42 | 43 | 44 | 45 |
4 | 45 | 44 | 43 | 42 | 41 |
5 | 33 | 32 | 42 | 15 | 41 |
对于以下查询:
select rollno,(mar+eng+maths+phy+chem)/5 as average from marks;
我得到的结果是:op
rollno | average |
---|---|
1 | 44.6000 |
2 | 40.4000 |
3 | 43.0000 |
4 | 43.0000 |
5 | 32.6000 |
现在要找到平均分最高的学生的学号,我应该写什么查询?
我尝试使用
select rollno,max( select (mar+eng+maths+phy+chem)/5 from marks ) from marks;
但是给我返回了语法错误
This syntax is wrong because the subquery returns multiple rows. Only one value can be used in the max function.
This is a better way -