这条SQL语句怎么写?
有两表A,B,其中字段都相等,有一字段为FLOAT型。
A:ID F B:ID F
1 10 1 7
2 4 2 -1
3 -3 5 -2
4 8 6 10
5 23
现在要A和B的ID相同则F相加,无相同的则照抄
结果:ID F
1 17
2 3
3 -3
4 8
5 21
6 10
这条语句怎么写啊?
问题点数:20、回复次数:4Top
1 楼hdhai9451(☆新人类☆)回复于 2004-12-02 22:15:14 得分 16
select id=isnull(a.id,b.id),F=case when a.id is null then b.F else a.F-isnull(b.F,0) end
from a
full join b on a.id=b.idTop
2 楼zlp321002(Life Is Good,Let's Shine)回复于 2004-12-02 22:29:29 得分 2
To: hdhai9451(Water Space--海洋空間)
相加是不是:
select id=isnull(a.id,b.id),F=case when a.id is null then b.F else a.F+isnull(b.F,0) end
from a
full join b on a.id=b.id
不知道老大的是不是对的??Top
3 楼yesyesyes()回复于 2004-12-03 08:54:51 得分 2
select id,sum(f) from
(select * from a
union all
select * from b)
group by idTop
4 楼tqhchina(spck)回复于 2004-12-08 12:25:52 得分 0
goTop




