求教SQL合并字段内容语句
表:temp
a、b为char类型,c为decimel
a b c
1 1 0.1
1 2 0.2
1 3 0.9
2 1 0.5
2 2 0.2
2 3 0.6
需要达到的效果:
a b c
1 1 0.3
1 3 0.9
2 1 0.7
2 3 0.6
即:a相同的时候,b=1或2的时候,保留b=1,c变为0.1+0.2
求语法…………
------解决方案--------------------大致如下:
;with a as
(select * from temp where b <> '2')
, b as
(select * from temp where b = '2')
select a.a, a.b, a.c+ISNULL(b.c,0) as c from a
left outer join b on a.a = b.a