2014-04-09 61 views
0

我是想選擇一個特定的記錄,它滿足如果column1 = column2 + column3選擇行另外兩個

SELECT gtt_id , 
    column1, 
    SUM(NVL(column2, 0) + NVL(column3, 0)) AS total 
FROM my_table where column1 = total 
GROUP BY gtt_id, 
column1; 

我收到以下錯誤條件:

ORA-00904: "TOTAL": invalid identifier

回答

1

您不應該在同一個查詢中使用total,因爲您需要將查詢包裝並在外部循環中使用該查詢。

SELECT gtt_id,column1,total 
FROM 
(
SELECT gtt_id , 
     column1, 
     SUM(NVL(column2, 0) + NVL(column3, 0)) total 
FROM my_table 
--where column1 = total 
GROUP BY gtt_id, 
column1 
) 
where column1 = total;