select jtbh,sex,hf,sf,
case when aa.hf='已婚' and aa.sex='女' and aa.sf='职工' then (select count(*) from 表 where jtbh=aa.jtbh and sex='男' and sf='子女') end 男孩数,
case when aa.hf='已婚' and aa.sex='女' and aa.sf='职工' then (select count(*) from 表 where jtbh=aa.jtbh and sex='女' and sf='子女') end 女孩数
from 表 aa
case when aa.hf='已婚' and aa.sex='女' and aa.sf='职工' then (select count(*) from 表 where jtbh=aa.jtbh and sex='男' and sf='子女') end 男孩数,
case when aa.hf='已婚' and aa.sex='女' and aa.sf='职工' then (select count(*) from 表 where jtbh=aa.jtbh and sex='女' and sf='子女') end 女孩数
from 表 aa
case when aa.hf='已婚' and aa.sex='女' and aa.sf='职工' then (select count(*) from 表 where jtbh=aa.jtbh and sex='男' and sf='子女') end 男孩数,
case when aa.hf='已婚' and aa.sex='女' and aa.sf='职工' then (select count(*) from 表 where jtbh=aa.jtbh and sex='女' and sf='子女') end 女孩数
from 表 aa
当符合的记录超过一条时,这样的case子查询是不允许的,有没有别的办法??!!