我手头Store_ID
有表中 s 的总付款,需要针对 s 结算/调整transactions_id
相应store_id
s 的付款。
可以按如下方式创建表:
--- CREATE STORE_PAYMENTS TABLE--- CONTAINS RECEIVABLE AGAINST RECEIPTS NOS FOR STROES-------
CREATE TABLE DBO.STORE_PAYMENTS
(STORE_ID VARCHAR(10) NOT NULL,
RECEIPT_NO VARCHAR(10) NOT NULL,
RECEIVABLE INT NOT NULL,
PAYMENT_ADJUSTED INT NOT NULL,
BALANCE INT NOT NULL)
GO
INSERT INTO DBO.STORE_PAYMENTS
(STORE_ID,RECEIPT_NO,RECEIVABLE,PAYMENT_ADJUSTED,BALANCE)
VALUES
('STR1',1,100,0,0),
('STR1',2,200,0,0),
('STR1',3,300,0,0),
('STR2',1,100,0,0),
('STR2',2,100,0,0),
('STR2',3,50,0,0),
('STR3',1,0,0,0),
('STR3',2,150,0,0),
('STR3',3,300,0,0)
---- CREATE STORE_BALANCE TABLE --- CONTAINS INFORMATION OF IN HAND PAYMENTS -----------------
CREATE TABLE DBO.STORE_BALANCE
(STORE_ID VARCHAR(10) NOT NULL,
PAYMENTS INT NOT NULL)
GO
INSERT INTO DBO.STORE_BALANCE
(STORE_ID,PAYMENTS)
VALUES
('STR1',600),
('STR2',700),
('STR3',300)
SELECT * FROM DBO.STORE_BALANCE
SELECT * FROM DBO.STORE_PAYMENTS
调整支付的顺序可能基于 RECEIPT_NO order 或 rowid。
突出显示的列中的所需输出: