0
我有兩張表,其中@ pending表是等待結算的未決資金錶,@settle表是爲了解決這個@ pending,但需要匹配每個記錄的確切金額(值)。但我無法弄清楚如何執行這個任務。任何人都有想法。完全匹配待結算金額與結算
declare @pending as table (id int, value decimal(18,4))
declare @settle as table (id int, value decimal(18,4))
insert into @pending (id, value) values (1, 500)
insert into @pending (id, value) values (2, 250)
insert into @pending (id, value) values (3, 100)
insert into @pending (id, value) values (4, 250)
insert into @settle (id, value) values (1,500)
insert into @settle (id, value) values (2,300)
insert into @settle (id, value) values (3,200)
預計結果: 記錄下面將不會匹配
insert into @pending (id, value) values (3, 100)
記錄下面要匹配
insert into @pending (id, value) values (1, 500)
insert into @pending (id, value) values (2, 250)
insert into @pending (id, value) values (4, 250)
insert into @settle (id, value) values (1,500)
insert into @settle (id, value) values (2,300)
insert into @settle (id, value) values (3,200)
row | pending_id | pending_value | pending_bal | match_amount | settle_id
------------------------------------------------------------------
1 1 500 0 500 1
2 2 250 0 250 2
3 4 250 200 50 2
4 4 250 0 200 3
所以這個問題到底是什麼? – Mureinik
對不起,我編輯過這個問題。其實我想問如何執行這個匹配的查詢。 – skywills