[英]How to use column alias of create table statement in underlying select-join statement?
I've run into a minor problem with a query I want to build. 我遇到一个要构建的查询的小问题。 The idea is to construct a new table based on a join on the same old table where some kind of "expensive" calculation is done.
想法是在相同的旧表上基于联接构造一个新表,在该旧表上进行某种“昂贵”的计算。
The problem 问题
I can not use the calculated result (alias) of the field list in the where (or on) clause of the underlying select. 我不能在基础选择的where(或on)子句中使用字段列表的计算结果(别名)。
Why not calculate it again? 为什么不再次计算呢?
SQL Statement SQL语句
CREATE TABLE `newTable` AS (
SELECT (*COMPUTATION*) AS `calculated`
FROM oldTable AS t1
JOIN oldTable as t2 ON (
t1.user != t2.user
AND *other conditions*
)
WHERE `calculated` < *some number*
);
I've already thought of using functions or something else, but I think it should be doable in one simple query. 我已经考虑过使用函数或其他方法,但是我认为它应该可以在一个简单的查询中使用。
Have you tried wrapping your inner query one more level?? 您是否尝试过将内部查询再包装一层?
CREATE TABLE `newTable` AS
( select PreQuery.Calculated
from ( SELECT (*COMPUTATION*) AS `calculated`
FROM oldTable AS t1
JOIN oldTable as t2 ON
( t1.user != t2.user
AND *other conditions*
) ) PreQuery
where PreQuery.Calculated < *some number*
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.