日期:2014-05-17 浏览次数:20454 次
SELECT COUNT(b.sex) AS num,b.sex FROM
(
SELECT CASE WHEN dbo.fn_getSexByid(A.idcard,1)!='未知' THEN dbo.fn_getSexByid(A.idcard,1) ELSE A.sex END as sex FROM
(
SELECT DISTINCT(tbp.idcard),tbp.sex
FROM t_house th
RIGHT JOIN t_BasePeople tbp
ON th.idcard_id = tbp.id
LEFT JOIN t_BaseHouse tbh
ON th.house_id = tbh.id
LEFT JOIN v_user u
ON tbh.SQ_ID = u.sq_id
WHERE tbp.idcard NOT LIKE '%.%' AND
) A
) B
WHERE b.sex IS NOT NULL
GROUP BY b.sex