Fellows,
I have a query as follows:
SELECT A.ID, B.ID, (HUGE SUBQUERY) as HS
FROM TABLE_A JOIN TABLE_B ON A.ID = B.ID
WHERE (HUGE SUBQUERY) > 0
I’d like to avoid repeating the subquery.
Is there any way to rewrite my WHERE as something like
WHERE HS > 0
Or I must turn my subquery into a join?
You could use a CTE: