我有类似的东西:
Select1 ...
,(fieldA - fieldB) AS Y,
,(Select2
(Select3 percent
From ...
Join....
Where ...
Order by some_date
Limit 1) AS X
From ...
Join...
Where ...
Order by some_date2
Limit 1) AS X
,(X * Y) AS output
From ...
Join ...
Join ...
在我需要重用嵌套选择返回的值之前,一切正常。
如何在"输出"的定义中重用X别名?柱吗
PS现在不要将代码作为A4以上的代码!它按预期工作,但眼睛很难。
答案 0 :(得分:1)
您可以再次使用另一个嵌套SELECT
来完成此操作。然后,这个新的最外层SELECT
可以访问X
和Y
。
Select0
...
,(X * Y) AS output
From (
Select1 ...
,(fieldA - fieldB) AS Y,
,(Select2
(Select3 percent
From ...
Join....
Where ...
Order by some_date
Limit 1) AS X
From ...
Join...
Where ...
Order by some_date2
Limit 1) AS X
From ...
Join ...
Join ...) AS values