sql - 使用 group by 子句连接结果
问题描述
我如何加入以下 2 个查询 查询 1
select phn,count(*) from table 1
group by phn
having count(*)>20
有了上面的结果,我需要加入表 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
推荐阅读
- tensorflow - 深度 LSTM 准确率未超过 50%
- android - Expo React Native 应用程序的音频在 iOS 中播放,但在 Android 中不播放
- sql - CockroachDB:简单的 SQL 查询没有响应
- java - JavaFX 中的倒数计时器
- openmp - 如何在 WSL 中运行 OpenMP?
- php - 在PHPSpreadsheet中垂直和水平居中文本
- winforms - 用于 WinForms 组件的 Nullable 属性的 NullableConverter
- rest - Java 控制器未收到来自 Postman 的 PUT 请求
- c++ - 将音频源元素动态链接到 gstreamer audiomixer 元素中
- node.js - Google Analytics 中的跳出率是如何计算的?