我有这张桌子Student
:
- ID(int,主键标识)
- 名称(varchar(20))
- 分数(整数)
- RecordDate(DateTime)
我需要选择该表的所有列以及一个额外的列,该列代表“得分”列的“总和”,具体取决于Name
学生的情况。
我尝试了这个但是没用
select S.Id,S.Name ,S.Score ,S.RecordDate, ( select Sum(Score) from Student where Name= S.Name) as All_Student_Score
from Student S;
如何更改此查询?
You can use a `JOIN`:
SELECT S.*,
T.All_Student_Score
FROM Student S
INNER JOIN (SELECT Name, SUM(Score) All_Student_Score
FROM Student) T
ON S.Name = T.Name;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句