日期:2014-05-17 浏览次数:20425 次
;with f as
(
select * from tb t where not exists(select 1 from tb where 姓名=t.姓名 and 次数>t.次数)
)
select sum(成绩) from f
;WITH a AS (
SELECT code+MAX(cishu)col1 FROM test
GROUP BY code
)SELECT SUM(chengji) FROM test WHERE code+cishu IN (SELECT *FROM a)
优化下:
SELECT SUM(成绩) FROM TB t WHERE not exists(select 1 from tb where 姓名=t.姓名 and 次数>t.次数)