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

求SQL語句.
A         B         C         字段

S1       20       1        
S1       10       1    
S2       30       1
S3       50       2  

要得到查詢的結果是
S1       30       1                          
S2       30       1
S3       50       2



------解决方案--------------------
select A,sum(B) as B,max(C) as C from 表 group by A

------解决方案--------------------
--直接分组即可

select A,sum(B) as B,C from 表 group by A,C
------解决方案--------------------
select A,sum(B) as B,C from tab group by A,C order by A,C
------解决方案--------------------
select A,sum(B) as B,C from 表 group by A,C

------解决方案--------------------
Select A,sum(B) B,C from 表名
group by A,C

------解决方案--------------------

select a,sum(b) as b ,c from tbl
group by a,c