Create Table TEST
(单据号 Varchar(10),
客户名称 Nvarchar(10),
单价 Int,
重量 Int,
总金额 Int,
已付账款 Int)
Insert TEST Select '10000001', N'中国集团', 30, 15, 450, 200
Union All Select '10000001', N'中国集团', 20, 6, 120, 200
GO
Select
单据号,
客户名称,
SUM(总金额) As 总金额,
已付账款,
SUM(总金额) - 已付账款 As 未付账款
From
TEST
Group By
单据号,
客户名称,
已付账款
GO
Drop Table TEST
--Result
/*
单据号 客户名称 总金额 已付账款 未付账款
10000001 中国集团 570 200 370
*/