I’m using a query like:
SELECT C1, C1+C2,C (C1+C2)*C3 FROM T1 WHERE C2='XX'
Now, the second column’s formula is C1+C2 and the third column is the second multiplied by C3.
So, what I want to know is, if something like this is possible:
SELECT C1,C1+C2 AS NEWC, NEWC*C3 FROM T1 WHERE C2='XX'
This query seems trivial, but actually I have a huge 4-line query over which I’d like to use a way out if there is one, since the query is getting lengthened pointlessly due to repeating the formula already stated in previous columns.
You can use subqueries to remove duplicate code:
Sometimes, the readability can be improved by moving the subquery to the
WITHclause: