I'm not a Database Administrator--just a Software Engineer. I would like to know if it is possible to reduce the following T-SQL query:
SELECT
SUM(Price * Quantity) as 'Total',
SUM(Price * Quantity) * 0.95,
FROM
SomeTables;
To something like this:
SELECT
SUM(Price * Quantity) as 'Total',
'Total' * 0.95,
FROM
SomeTables;
Note: This is just a sample to clarify/support my question. My current SQL query is larger and more complex than this.
ORDER BYclause can reference assigned aliases in the same query. I suggest declaring a CTE that computes the first value, and then computing the second value in a query against that CTE. – Nick Chammas May 29 '12 at 22:07Common Table Expression? – Rubens Mariuzzo May 29 '12 at 22:12