Reuse Subquery from Select Expression in WHERE-Cla

2019-05-10 00:10发布

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条回答
\"骚年 ilove
2楼-- · 2019-05-10 00:46

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'
查看更多
登录 后发表回答