I'm trying to use an alias inside a subquery in a select statement like the one below:
SELECT
InvoiceId,
InvoiceTotal,
(SELECT
AVG(InvoiceTotal)
FROM Invoices) AS InvoiceAverage,
InvoiceTotal - (SELECT InvoiceAverage)
FROM Invoices;
When I try to execute the query I get this error:
'Invalid column name 'InvoiceAverage'.