You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写高效PSQL查询,统计目标操作最新记录后的记录数

高效统计符合条件的Changelog记录数

表结构定义

create table changelogs
(
    created_at      timestamp,
    user_action     varchar(255) default ''::character varying not null,
    id              serial
);

需求说明

统计所有**创建时间晚于指定user_action(如'target'、'target2'对应最新记录创建时间)**的记录总数。

高效PSQL查询实现

select count(*)
from changelogs
where created_at > (select max(created_at)
                    from changelogs
                    WHERE user_action in ('target', 'target2')
)

内容的提问来源于stack exchange,提问作者Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 03:54:12