2 weixin 36197229 weixin_36197229 于 2016.09.21 11:00 提问

两个表求和的数值相减

图片说明
select dm1,SUM(je) from lsxhd where rq>='2015-03-01' and rq<='2015-03-31' and dm1='az' GROUP by dm1

select dm1,SUM(je) from lsthd where rq>='2015-03-01' and rq<='2015-03-31' and dm1='az' GROUP by dm1

lsxhd求和数值减lsthd求和数值,怎么写语句求大神帮忙!!!!!

2个回答

guwei4037
guwei4037   Ds   Rxr 2016.09.21 11:08

举个例子:

 declare @num1 int , @num2 int
set @num1 = (select id from test where id = 17)
set @num2 = (select id from test where id = 10)
select @num1-@num2 as num
yflxc
yflxc   2016.09.21 11:16

select a.num1-b.num2 from (select sum(je) num1 from lsxhd) a,(select sum(je) num2 from lsthd) b

seeze
seeze 回复weixin_36197229: 两个子查询,分别套用你上面的SQL语句就行了
大约一年之前 回复
weixin_36197229
weixin_36197229 时间段没有啦
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片