读书人

求一语句,取最大的求和解决方法

发布时间: 2012-02-01 16:58:19 作者: rapoo

求一语句,取最大的求和
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

读书人网 >SQL Server

热点推荐