sql - SQL/Postgres:查找具有相同值的元组(对于另一列中的给定值)
问题描述
我的表 ANSWERS_T 是
id answer_date_val event_id
.. ... ...
103 2019-10-18 09:30:00.000 145
104 2019-10-18 09:35:00.000 145
105 2019-10-18 10:45:00.000 146
106 2019-10-18 10:50:00.000 146
..
我的查询需要找到 ANSWERS_T 行,其中同一 event_id 有多个相同的 answer_date_val。
这是在 Postgres 中。
解决方案
如果您需要 answer_date_val 和 event_id 的重复条目,您可以尝试使用子查询来重复连接到基表
select *
from ANSWERS_T a
inner join (
select event_id, answer_date_val
from ANSWERS_T
group by event_id, answer_date_val
having count(*) >= 2
) t on t.event_id= a.event_id
and t.answer_date_val = a.answer_date_val
推荐阅读
- ios - UICollectionView:更新节页脚标题
- amazon-web-services - 为什么 CloudFront 在压缩前无法保存 ETag?
- ios - 推送特定的 viewController
- android - 清单合并失败:属性 application@appComponentFactory
- react-native - 在 TabBar 控制器内向 RNN 添加持久视图
- d3.js - DC.js - 复合图表 - 访问 renderlet 内的堆栈号并使用网格线问题
- c# - 编写了一个控制台应用程序来使用 RestSharp 推送数据,但是当我尝试创建一个 Windows 服务时它不起作用
- javascript - 错误:没有错误处理程序。是否包含平台模块(BrowserModule)?尝试从 jsf 页面加载 Angular 应用程序时
- android - kotlin recycleradapter bindviewholder
- c# - 如何从另一个名为 ControlPanel 的表单更新 Main.cs 中的 timer.interal