如果状态终止则提取SQL Server,然后不显示该ID的先前记录

问题描述 投票:0回答:1

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

sql sql-server
1个回答
0
投票

如果我理解正确你需要:

select t.*
from table t
where not exists (select 1 from table t1 where t1.agent = t.agent and t1.status = 'terminated');
© www.soinside.com 2019 - 2024. All rights reserved.