select 地区, 男同志 + 女同志 as 总人数,男同志,女同志 from 
(
 select 地区,count(*) as 男同志,0 from where 性别='男' tablename group by 地区 
union 
select 地区,0,count(*) as 女同志 from where 性别='女' tablename group by 地区 
) group by 地区

解决方案 »

  1.   

    select 地区, 男同志 + 女同志 as 总人数,男同志,女同志 from 
    (
     select 地区,count(*) as 男同志,0 from tablename where 性别='男' group by 地区 
    union 
    select 地区,0,count(*) as 女同志 from tablename where 性别='女' group by 地区 
    ) group by 地区
      

  2.   

    select 地区,count(*) as all,
    (select 地区,count(*) from tablename where 性别='男' group by 地区) as man,
    (select 地区,count(*) from tablename where 性别='女' group by 地区) as woman
    from tablename group by 地区
      

  3.   

    artman() ,yjs_lh(长风浪子) 的查询好像不太复合要求,union 是上下连接
    两个查询,所以上面的查询应该可以吧。