2016-12-27 7 views
0

あいまいですは参加:列への参照は、私がCONT_IDパラメータで2つのテーブルに参加したい

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:COLUMNのCONT_ID TO REFERENCEは曖昧である

+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を指定する必要があります。代わりにdo

COUNT(DISTINCT c.CONT_ID) 
関連する問題