从 WHERE 子句中的选择表达式中重用子查询

2022-01-23 00:00:00 alias subquery mysql

当然不能写

SELECT (some subselect) AS blah FROM t WHERE blah = 'const'

最好的方法是什么?

  • SELECT (some subselect) FROM t WHERE (some subselect) = 'const'?
  • 查看?
  • 存储函数?
  • 有吗?
  • 其他?

推荐答案

你可以将 (some subselect) 作为表格移动到 FROM 中:

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'

相关文章