解决方案#1:
SELECT src.*, src.[10%], (src.[10%] + src.InvoiceTotal) AS [Plus 10%]
FROM
(
SELECT InvoiceTotal, (InvoiceTotal * .10) AS [10%]
FROM Invoices
WHERE InvoiceTotal - PaymentTotal - CreditTotal > 500
) src
ORDER BY src.InvoiceTotal DESC;
解决方案#2:
;WITH BaseQuery
AS
(
SELECT InvoiceTotal, (InvoiceTotal * .10) AS [10%]
FROM Invoices
WHERE InvoiceTotal - PaymentTotal - CreditTotal > 500
)
SELECT src.*, src.[10%], (src.[10%] + src.InvoiceTotal) AS [Plus 10%]
FROM BaseQuery src
ORDER BY src.InvoiceTotal DESC;
解决方案#3:
SELECT i.InvoiceTotal, x.[10%], (x.[10%] + i.InvoiceTotal) AS [Plus 10%]
FROM Invoices i
CROSS APPLY ( SELECT (i.InvoiceTotal * .10) AS [10%] ) x
WHERE i.InvoiceTotal - i.PaymentTotal - i.CreditTotal > 500
ORDER BY i.InvoiceTotal DESC;