不支持的列别名oracle

时间:2015-01-20 07:49:43

标签: sql database oracle

我有问题,因为我得到错误不支持的列别名,我不知道原因在哪里。有谁知道答案,可以帮助吗?在此先感谢:)代码:

with
ContractByRole (intermediary_nr, beneficiary_role, contract_nr) as (
  select intermediary_nr, beneficiary_role, max(contract_nr) contract_nr
  from boscs.atcs_commission_beneficiary
  where beneficiary_role in( 'LEAD', 'SUP_FOR_LEAD', 'COAGENT' )
      and intermediary_nr is not null
  group by intermediary_nr, beneficiary_role
)

AllRoles(contract_nr) as (
  select   contract_nr
  from     ContractByRole
  group by contract_nr
  having count(*) = 3
)

select  cbr.*
from    ContractByRole cbr
join    AllRoles       ar
    on  ar.contract_nr = cbr.contract_nr;

错误显示在这个地方:

ContractByRole(intermediary_nr, beneficiary_role, contract_nr) as (

1 个答案:

答案 0 :(得分:0)

您错过了逗号来分隔WITH子句中的两个子查询 -

编辑试试这个:(不确定你是否真的需要递归子查询)

WITH contractbyrole 
     AS 
     ( 
              SELECT   intermediary_nr, 
                       beneficiary_role, 
                       Max(contract_nr) contract_nr 
              FROM     boscs.atcs_commission_beneficiary 
              WHERE    beneficiary_role IN( 'LEAD', 
                                           'SUP_FOR_LEAD', 
                                           'COAGENT' ) 
              AND      intermediary_nr IS NOT NULL 
              GROUP BY intermediary_nr, 
                       beneficiary_role 
     ) 
    , --> here is the missing comma
     allroles 
     AS 
     ( 
              SELECT   contract_nr 
              FROM     contractbyrole 
              GROUP BY contract_nr 
              HAVING   count(*) = 3 
     ) 
SELECT cbr.* 
FROM   contractbyrole cbr 
JOIN   allroles ar 
ON     ar.contract_nr = cbr.contract_nr;