select 单位, sum(case 性别 when '男' then 1 else 0 end) as [男], sum(case 性别 when '女' then 1 else 0 end) as [女], sum(case 学历 when '大专' then 1 else 0 end) as [大专], sum(case 学历 when '本科' then 1 else 0 end) as [本科], sum(case 最高学历 when '本科' then 1 else 0 end) as [最高学历本科], sum(case 最高学历 when '研究生' then 1 else 0 end) as [最高学历研究生] from tablename group by 单位