尝试创建一个包含到期余额、利息费用、到期总额和付款计划的结果集。他们的方式我正在编码它似乎工作,但它似乎很不雅。有没有办法利用变量使代码更清晰?
SELECT
CustFName, CustLName, CustPhone,
SUM(InvoiceAmount - PaymentAmount) AS BalanceDue,
SUM(InvoiceAmount - PaymentAmount)*.195 AS InterestCharge,
SUM(InvoiceAmount - PaymentAmount) + SUM(InvoiceAmount - PaymentAmount) *.195 AS TotalDue,
(SUM(InvoiceAmount - PaymentAmount) + SUM(InvoiceAmount - PaymentAmount) *.195)/4 AS PaymentPlan
FROM
Customer
JOIN
Vehicle ON Customer.CustomerID = Vehicle.CustomerID
JOIN
Invoice ON Vehicle.VehicleID = Invoice.VehicleID
WHERE
InvoiceAmount - PaymentAmount > 400
GROUP BY
CustFName, CustLName, CustPhone