2016-12-27 63 views
0

我想加入2代表與CONT_ID參數加入:參照列是不明確的

select (case when age_years >= 18 and age_years < 30 then '18-29'  
     when age_years < 50 then '30-49'        
     when age_years < 70 then '50-69'        
      when age_years < 100 then '70-100'        
     end) as age_range,            
      count(DISTINCT CONT_ID) as num,        
     SUM(ACAUT)/COUNT(*) as avg     
    from CLIENT c           
     left join PAYTB t          
     on c.CONT_ID = t.CONT_ID           
    group by (case when age_years >= 18 and age_years < 30 then '18-29' 
     when age_years < 50 then '30-49'         
     when age_years < 70 then '50-69'         
     when age_years < 100 then '70-100'         
     end)                
     order by min(age_years); 

錯誤

SQLCODE = -203,ERROR:基準柱CONT_ID是模糊

+2

而不是'count(DISTINCT c.CONT_ID)'。 – jarlh

+0

如果你有'count(DISTINCT CONT_ID)as num',你已經爲你的表('c'或't')...'count(DISTINCT c.CONT_ID)創建的別名添加爲num'或' count(DISTINCT t.CONT_ID)as num' –

+0

這固定了連接。 – bastel

回答

1

您必須指定在COUNT DISTINCT中使用哪一列CONT_ID。反而做

COUNT(DISTINCT c.CONT_ID)