一起拖曳同一张桌子

问题描述:

嗨朋友
我有两个表,两个列(代码,成本)
我想减去这张表

table1 table2
---------------- ----------------
验证码|费用代码|费用
------------- -------------
1 | 100 1 | 50
2 | 200 2 | 100
3 | 300 3 | 200
4 | 400


结果=表1-表2
----------------
验证码|费用
-------------
1 | 50
2 | 100
3 | 100
4 | 400


请指导我...

hi friends
i have tow same table with tow columns(Code , Cost)
and i wanna subtract this tables

table1 table2
---------------- ----------------
code | cost code | cost
------------- -------------
1 | 100 1 | 50
2 | 200 2 | 100
3 | 300 3 | 200
4 | 400


result = table1 - table2
----------------
code | cost
-------------
1 | 50
2 | 100
3 | 100
4 | 400


please guide me ...

您可以为此使用左连接.例子
you can use left join for this. example
select code, a.cost - isnull(b.cost,0) from table1 a 
left join table2 b on a.code = b.code