日期:2014-05-19  浏览次数:20708 次

MM马上给分,分组语句怎样写?
我要读取表A中的所有字段,同时得到字段sum(Grade)   as   GrageSum,按StudentName分组的,就是说相等StudentName,只取出其中一行数据,但是要汇总相等StudentName所有的Grade,谢谢!

------解决方案--------------------
select studentname,sum(grade),max(col1),max(col2),...max(coln)
from tb
group by studentname
------解决方案--------------------
select studentname,col1,col2,..., --写全字段,除了grade
(select sum(grade) from tb where studentname=a.studentname) as grade
from tb a
where not exists (
select 1 from tb
where studentname=a.studentname
and key <a.key
)