SQL查询如何分类汇总。如表中有年龄字段,用数字表示,查询结果像表示成 年龄段 人数 20-30 5 30-40 6

如题所述

select sum(case when  年龄 > 20 and 年龄 <= 30 then 1 else 0 end) "20-30",
           sum(case when  年龄 > 30 and 年龄 <= 40 then 1 else 0 end) "30-40",
         ..............
 
from tabxxx

           

温馨提示:答案为网友推荐,仅供参考
相似回答