如何编写高效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
相关产品推荐
相关产品推荐

