select A.编号, A.余额+isnull(B.金额,0) from 单位列表 A left join ( select 单位编号, sum(金额) as '金额' from 收款流水 where 收款日期<'2005-03-01' group by 单位编号 ) B on A.编号=B.单位编号
select 单位编号,sum(金额) from table where 时间<"2005-03-01" group by 单位编号
select a.单位编号,sum(a.金额)+sum(b.金额) as 金额 from table1 a,table2 b where b.收款日期<2005-03-01 group by 单位编号
单位列表为table1 收款流水为table2 select 单位编号,(余额+total) as 余额 from table1 left join (select 单位编号,sum(金额) as total from table2 where 收款日期<'2005-03-01 23:59:59' group by 单位编号) tt on table1.单位编号=tt.单位编号
如果是更新:updte A set 余额=A.余额+isnull(B.金额,0) from 单位列表 A left join ( select 单位编号, sum(金额) as '金额' from 收款流水 where 收款日期<'2005-03-01' group by 单位编号 ) B on A.编号=B.单位编号
select a.单位编号,sum(a.金额)+sum(b.金额) as 金额 from table1 a,table2 b where b.收款日期<2005-03-01 group by 单位编号
select t1.单位编号,t1.金额+t2.j from(select 单位编号,sum(金额) as j from table2 where 收款日期<2005-03-01 group by 单位编号) as t2 inner join table1 as t1 on t1.单位编号=t2.单位编号
A.余额+isnull(B.金额,0)
from 单位列表 A
left join (
select 单位编号,
sum(金额) as '金额'
from 收款流水
where 收款日期<'2005-03-01'
group by 单位编号
) B on A.编号=B.单位编号
where b.收款日期<2005-03-01
group by 单位编号
select 单位编号,(余额+total) as 余额 from table1 left join (select 单位编号,sum(金额) as total from table2 where 收款日期<'2005-03-01 23:59:59' group by 单位编号) tt on table1.单位编号=tt.单位编号
set 余额=A.余额+isnull(B.金额,0)
from 单位列表 A
left join (
select 单位编号,
sum(金额) as '金额'
from 收款流水
where 收款日期<'2005-03-01'
group by 单位编号
) B on A.编号=B.单位编号
where b.收款日期<2005-03-01
group by 单位编号
from(select 单位编号,sum(金额) as j from table2 where 收款日期<2005-03-01 group by 单位编号) as t2
inner join table1 as t1
on t1.单位编号=t2.单位编号