sql - 在特定列 postgres 中选择具有最大值的组中的行
问题描述
我有一个看起来像这样的数据库表。
id account_id action time_point
3 234 delete 100
1 656 create 600
1 4435 update 900
3 645 create 50
我需要按 id 对该表进行分组,并选择 time_point 具有最大值的特定行。
结果表应如下所示:
id account_id action time_point
3 234 delete 100
1 4435 update 900
谢谢你的帮助,qwew
解决方案
检查这个。
select * from x
where exists (
select 1 from x xin
where xin.id = x.id
having max(time_point) = time_point
);
推荐阅读
- angular - 在离子 4 中返回堆栈时出现问题
- grpc - grpc.Dial() 是否创建 http/2 连接?
- html - 如何在 Bootstrap 4 的两列之间添加一条垂直线
- algorithm - 最佳优先搜索中使用了哪种启发式函数?
- conv-neural-network - YOLO .cfg 文件中的 scale 和 step 值是什么意思?
- amazon-web-services - 使用 AWS 实施 ADFS3.0
- azure-active-directory - Azure AD B2C:返回到用户旅程中上一个编排步骤的选项
- javascript - 在另一个节点实例中运行节点
- windows - Docker + EmberCLI + Windows = 不工作
- java - 在方法内分配变量