开发者

Reuse Subquery from Select Expression in WHERE-Clause

开发者 https://www.devze.com 2023-02-26 20:05 出处:网络
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?

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?
  • St开发者_StackOverflowored Function?
  • HAVING?
  • other?


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'
0

精彩评论

暂无评论...
验证码 换一张
取 消