2016-12-26 18 views
0

年齢パラメータAGE_YEARSのテーブルINFOがあります。sql ibm db2グループ年齢範囲

AGE_RANGE COUNT 
18-29  400 
30-49  500 
50-69  ??? 
70-99  ??? 

がどのようにselect文は、このために次のようになります。 私はこのような出力が必要ですか?

答えて

0

あなたはcaseを使用することができます。

select (case when age_years >= 18 and age < 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(*) 
from REDACTED 
group by (case when age_years >= 18 and age < 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); 
関連する問題