<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;

 

全部评论

相关推荐

11-07 13:31
怀化学院 Java
勇敢牛牛不怕难:又疯一个
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务