我有以下(mysql)SQL查询:
select a.id, a.name, count(*) as humans
from humans h1, areas a
where h1.gender = 'Female' and h1.area_id = a.id
group by area_id
having count(*) > (
select count(*)
from humans h2
where h2.gender = 'Male' and h1.area_id = h2.area_id
group by area_id
)
or not exists (
select *
from humans h2
where gender = 'Male' and h1.area_id = h2.area_id
group by area_id
)
这基本上显示了所有由女性主导的领域。
我将如何将其转换为流畅的语法?
从网站上的示例中,我不确定如何使用具有相关性的子查询。