日期:2014-05-18 浏览次数:20569 次
--> 测试数据: [进货] if object_id('[进货]') is not null drop table [进货] go create table [进货] (进货单ID int,总额 int,支付余额 int) insert into [进货] select 1,100,0 union all select 2,50,20 union all select 3,200,170 --> 测试数据: [付款] if object_id('[付款]') is not null drop table [付款] go create table [付款] (付款单ID int,总额 int,已付款 int) insert into [付款] select 1,50,0 union all select 2,110,1 --> 测试数据: [映射] if object_id('[映射]') is not null drop table [映射] go create table [映射] (映射表ID int,进货单ID int,付款单ID int,金额 int) insert into [映射] select 1,1,1,20 union all select 2,1,2,80 union all select 3,2,1,30 union all select 4,3,2,30 select p.映射表ID, p.进货单ID, p.付款单ID, p.金额, i.支付余额, o.已付款 from [映射] p join [付款] o on o.付款单ID=p.付款单ID join [进货] i on i.进货单ID=p.进货单ID --where i.支付余额=0 and 已付款=1 映射表ID 进货单ID 付款单ID 金额 支付余额 已付款 ----------- ----------- ----------- ----------- ----------- ----------- 1 1 1 20 0 0 2 1 2 80 0 1 3 2 1 30 20 0 4 3 2 30 170 1 (4 行受影响)
------解决方案--------------------