SQL Developer:无效的标识符错误

时间:2015-07-31 18:47:23

标签: sql oracle case

这是我的查询中有错误的部分:

, case  when dsi.distributor_id in 
('ALBQA','ASGLA','ASGNY','ASGR1','ASGSF','BIKU9','COAUU','CSWHP','DPIB1','DPID9',
'DPISP','DPISQ','EAS3X','GEP79','GRG8V','NACY7','NOSYK','ORGK7','PETR1','TOP0U',
    'UNFIA','UNFIL','UNFIQ','UNFIS','UNMQ9','KOSI8','KEHEN','CSNYC','ALBQA','ALC6Y','BAM7D','BIKU9','CLCE0','COAUU','CSWHT','EAS3X','FOUXU','GEP79',
'GRG8V','HED9Q','LAOJD','MCLFS','NOSYK','ORGK7','UNMQ9','OMAH1'
)
      then 'Distributor'
      else 'Direct'
      end as is_direct
, SUM(dsi.cost) AS tot_cost

, SUM(CASE WHEN is_direct = 'Direct' THEN dsi.cost ELSE 0 END ) AS Direct_cost

它说is_direct是一个无效的列,但我已经在上面指出了它。因此,我想知道你是否可以帮助我找到我出错的地方。

1 个答案:

答案 0 :(得分:0)

查询中定义的列不能在查询的其他位置使用,无论是在其他列中,还是WHERE子句等。

我建议将这些计算放入子查询中,或使用WITH AS