在sql中怎么查询 同一列的两行之和

select (a/x)as a1,(b/x)as b1 from table where id='1'
select (a/x)as a2,(b/x)as b2 from table where id='2'
我想就 a1+a2 和 bi+b2 的和

第1个回答  2006-11-20
select nvl(a1,0)+nvl(a2,0) as a,nvl(b1,0)+nvl(b2,0) as b
from(
select (a/x)as a1,(b/x)as b1 from table where id='1'
union all
select (a/x)as a2,(b/x)as b2 from table where id='2' )
第2个回答  2006-11-20
select sum(a/x) as aa,sum(b/x) as bb from table where id=1 or id=2本回答被提问者采纳
相似回答
大家正在搜