select 性别,case when 年龄 between 20 and 29 then 1 else 0 end [20-29],case when 年龄 between 30 and 39 then 1 else 0 end [30-39],case when 年龄 between 40 and 49 then 1 else 0 end [40-49]from 表名group by 性别以上使用于大部分数据库只是在起别名上,只适用于sqlserveroracle的话起别名select 性别,case when 年龄 between 20 and 29 then 1 else 0 end "20-29",case when 年龄 between 30 and 39 then 1 else 0 end "30-39",case when 年龄 between 40 and 49 then 1 else 0 end "40-49"from 表名group by 性别mysql的话select 性别,case when 年龄 between 20 and 29 then 1 else 0 end `20-29,case when 年龄 between 30 and 39 then 1 else 0 end `30-39`,case when 年龄 between 40 and 49 then 1 else 0 end `40-49from 表名group by 性别
Copyright © 广州京杭网络科技有限公司 2005-2024 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有