2015-02-23 75 views
1

如何正確運行此查詢:如何創建temp col? MySQL查詢

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

我想創建變量SUM1和其他功能使用它!

+0

'選擇2,4'?你能更好地描述你想要做什麼嗎? – 2015-02-23 13:02:20

+0

@GordonLinoff其實我的查詢比較複雜!我會編輯答案,只給一分鐘 – david 2015-02-23 13:03:45

回答

3

使用子查詢別名表達式:

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