Select [<20岁]=sum(case when 年龄<20 then 1 else 0 end),
       [20-35岁]=sum(case when (年龄>20 and 年龄<=35) then 1 else 0 end),
       [>35岁]=sum(case when 年龄>35 then 1 else 0 end)
from table

解决方案 »

  1.   

    Select [<20岁]=sum(case when 年龄<20 then 1 else 0 end),
           [20-35岁]=sum(case when (年龄>20 and 年龄<=35) then 1 else 0 end),
           [>35岁]=sum(case when 年龄>35 then 1 else 0 end)
    from table
      

  2.   

    Select [<20岁]=sum(case when 年龄<20 then 1 else 0 end),
           [20-35岁]=sum(case when (年龄 between 20 and 35) then 1 else 0 end),
           [>35岁]=sum(case when 年龄>35 then 1 else 0 end)
    from table
      

  3.   

    妙!Select [<20岁]=sum(case when 年龄<20 then 1 else 0 end),
           [20-35岁]=sum(case when (年龄>20 and 年龄<=35) then 1 else 0 end),
           [>35岁]=sum(case when 年龄>35 then 1 else 0 end)
    from table
      

  4.   

    Select [<20岁]=count(case when 年龄<20 then 姓名 else 0 end),
           [20-35岁]=count(case when (年龄>20 and 年龄<=35) then 姓名 else 0 end),
           [>35岁]=count(case when 年龄>35 then 姓名 else 0 end)
    from table