问题
Of course it isn't possible to write
SELECT (some subselect) AS blah FROM t WHERE blah = 'const'
What is the best way to do this?
SELECT (some subselect) FROM t WHERE (some subselect) = 'const'
?- View?
- Stored Function?
- HAVING?
- other?
回答1:
you can move (some subselect)
as table in the FROM
:
SELECT s.blah
FROM t, (some subselect) s
WHERE t.id = s.id
AND s.blah = 'const'
来源:https://stackoverflow.com/questions/5720983/reuse-subquery-from-select-expression-in-where-clause