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

求一语句,取最大的求和
a             b
100         1
150         1
200         1  
125         2
85           2

-------------
结果
200+125=325


如何写语句.




------解决方案--------------------
select sum(a) from (select max(a) as a from table group by b) aa
------解决方案--------------------
select sum(a) from [Table] a where not exists(select 1 from [table] where b=a.b and a> a.a)
------解决方案--------------------
select sum(a) from (SELECT max(a) a,b FROM TABLE GROUP BY b) tbale2
------解决方案--------------------
a b
100 1
150 1
200 1
125 2
85 2

-------------
结果
200+125=325


---------------------------
select sum(a)as a from
(
select max(a)as a ,b from t group by b

)b