如何创建临时col? mysql查询

时间:2015-02-23 13:00:46

标签: mysql sql

如何正确运行此查询:

SELECT 
sum(1+1) as sum1,
sum(sum1 + 2) as sum2

我想创建变量sum1并在其他函数中使用它!

1 个答案:

答案 0 :(得分:3)

使用子查询来表示别名:

select  sum1
,       sum(sum1 + 2) as sum2
from    (
        select  sum(1+1) as sum1
        ) as SubQueryAlias