Reuse Subquery from Select Expression in WHERE-Clause

馋奶兔 提交于 2019-12-07 16:32:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!