日期:2014-05-17  浏览次数:20603 次

统计小问题
列a 列b
101 5
102 7
101 6
102 8
105 7
 。 。
 。 。
 。 。

要得到列a相同列b相加如下,求高手解答如何编,小弟刚学不久
101 11
102 15
105 7
 。 。
 。 。
 。 。


------解决方案--------------------
try this,

select 列a,sum(列b) '列b'
 from [表名]
 group by 列a

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

create table #T(
a int null,
b int null
)

insert into #T 
select 101,5 union all
select 102,7 union all
select 101,6 union all
select 102,8 union all
select 105,7 

select A,SUM(b) from #T group by a 
结果

A (无列名)
101 11
102 15
105 7