<span>连接查询</span>
1、差集。
select c.id,c.num from
(select a.`村寨id` id, count(1) num from 农户签约详细信息 a group by a.`村寨id`) c
left join
(select b.`村寨id` id, count(1) num from 房间 b group by b.`村寨id`)d
on c.id = d.id
where c.num < d.num;
SELECT DISTINCT t.id FROM
(
select a.`村寨id` id, count(1) num from 农户签约详细信息 a group by a.`村寨id`
UNION ALL
select b.`村寨id` id, count(1) num from 房间 b group by b.`村寨id`
) t
GROUP BY t.id,t.num
HAVING count(*) <2;