首页 > 解决方案 > SQL Server 提取状态是否终止,然后不显示该 ID 的先前记录

问题描述

我需要帮助如何编写一个 sql 命令我有几个代理,例如从一月到二月它们是活跃的,三月它们被终止了。如果他们在最后一个日期被终止,那么如何编写查询然后甚至不向我显示该代理的先前记录?

标签: sqlsql-server

解决方案


如果我理解正确,您需要:

select t.*
from table t
where not exists (select 1 from table t1 where t1.agent = t.agent and t1.status = 'terminated');

推荐阅读