当前位置: 代码迷 >> Sql Server >> 统计小疑点
  详细解决方案

统计小疑点

热度:49   发布时间:2016-04-24 19:19:21.0
统计小问题
列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
  相关解决方案