使用 group by 子句连接结果

Join results using group by clause

我如何加入以下 2 个查询 查询 1

select phn,count(*) from table 1 
group by phn
having count(*)>20 

根据以上结果我需要加入table 2 来获取id

查询 2

select count(distinct id) from table 2 
where (result_of_query1).phn=table 2.phn

您可以通过以下方式加入:

select count(distinct id)
from table2 t2
inner join (
    select phn
    from table1 
    group by phn
    having count(*) > 20 
) t1 on t1.phn = t2.phn