我的数据集低于数据集。我需要找到ID已“创建”但未“删除”的列表
TimeStamp ID Reason
2:38:46 1 created
2:39:46 2 Created
2:40:46 1 Removed
2:42:46 3 Created
2:45:46 2 Updated
2:48:46 4 Created
2:45:46 3 Removed
结果应该是针对上述数据集:
2:39:46 2 Created
2:48:46 4 Created
答案 0 :(得分:1)
not exists
:
select t.*
from t
where t.reason = 'Created' and
not exists (select 1 from t t2 where t2.id = t.id and t2.reason = 'Removed');