select distinct t1.name,t1.stuid,t2.allscore from stuscore t1,
(
select stuid,sum(score) as allscore from stuscore group by stuid
)t2
where t1.stuid=t2.stuid
order by t2.allscore desc
方法二:
SQL code
select stuid,name,sum(score) as allscore from stuscore group by stuid,name
我经常用方法二,难道真的影响查询结果的准确?!!! 好担心,项目都写了一半了
------解决方案-------------------- select stuid,max(name),sum(score) as allscore from stuscore group by stuid