我试图选择特定记录,满足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
答案 0 :(得分: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;