join:对列的引用不明确

时间:2016-12-27 10:13:22

标签: sql join db2

我想使用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,错误:对列的参考CONT_ID是不正确的

1 个答案:

答案 0 :(得分:1)

您必须在CONT_ID中指定要使用的列COUNT DISTINCT。而是做

COUNT(DISTINCT c.CONT_ID)