选择all并选择sum的Mysql查询

时间:2014-07-20 11:03:04

标签: mysql select sum

我这里有学生表,有字段:idnamescore

结果将获得4列:idnamescore和得分总和。

我需要结合两行,我可以结合两个命令吗?

select * from student
select sum(score) from student

2 个答案:

答案 0 :(得分:1)

select *, (select sum(score) from student) as score_sum
from student

答案 1 :(得分:0)

我有一个类似的案例。对我来说,以下工作有效:

SELECT *, sum(score) as score_sum FROM student

因此不需要额外的SELECT,但请确保*在sum()之前