2014-04-09 25 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;