select code,name,amount,client
from table1
group by code,client
union
select code,name,amount * -1,client
from table2
group by code,client
order by code
不知行不行。试试吧
或者
select code,name,
(select sum(amount) from tablea b where a.code = b.code and a.client = b.client) -
(select -1 * sum(amount) from tableb c where a.code = c.code and a.client = c.client)
as amount,client
from tablea a
group by code,name,client
having (select sum(amount) from tablea b where a.code = b.code and a.client = b.client) -
(select -1 * sum(amount) from tableb c where a.code = c.code and a.client = c.client) > 0
[此贴子已经被作者于2007-1-25 17:56:03编辑过]