日期:2014-05-17 浏览次数:20667 次
SELECT A.house_addr,A.scode,A.SQ_ID,A.stype,A.fzxm,A.fzdh,A.fzsfz,ROW_NUMBER() OVER(ORDER BY A.id) AS id,A.person_count FROM
(
SELECT tbh.house_addr,tbh.scode,tbh.SQ_ID,tbh.stype,tbh.fzxm,tbh.fzdh,tbh.fzsfz,tbh.id,tbh.person_count
FROM t_BaseHouse tbh
WHERE
tbh.house_addr IN (SELECT tbh2.house_addr FROM t_BaseHouse tbh2 GROUP BY tbh2.house_addr HAVING COUNT(tbh2.house_addr)=1)
--((SELECT COUNT(*) FROM t_BaseHouse tbh2 WHERE tbh.house_addr = tbh2.house_addr)>2)
) A
RIGHT JOIN
(
SELECT DISTINCT(tbh2.house_addr) FROM
t_BaseHouse tbh2 INNER JOIN v_user u2
ON u2.sq_id = tbh2.SQ_ID
WHERE tbh2.last_checker IS NULL
) B
ON B.house_addr = A.house_addr
WHERE A.person_count IS NULL
GO
这个条件放到 on之后
A.person_count IS NULL