1
Date time   Record ID   Action
9/9/2018 7:03   102 Support 
9/9/2018 7:03   102 hello
9/10/2018 7:03  103 Fetch it
9/10/2018 7:03  103 Ask it
9/10/2018 7:03  103 enable it 
9/9/2018 5:03   104 support 
9/9/2018 4:03   104 Fetch it
9/11/2018 7:03  105 Support 
9/11/2018 8:03  105 Support 
9/12/2018 5:03  106 end it
9/12/2018 6:03  106 Fetch it
9/12/2018 7:03  106 Support 

我想要实现的是

记录 ID 计数,其中操作列中的最后一条记录(按升序排列的日期时间)应该只有一次支持,并且每个 ID 支持之后都应该没有记录

在上表中,只有记录 ID 的 106 和 104 在操作列中仅支持一次,并且支持按日期时间升序排序后没有记录所以我需要计数(2)/显示 104 和 106 ..

有人可以帮忙解决这个问题吗!!!...

4

1 回答 1

2

Hmmm. One method uses aggregation and having:

select recordid
from t
group by recordid
having min(case when action = 'Support' then datetime end) = max(datetime);

This essentially says that the first time "Support" is seen is the latest time for the recordid.

于 2018-09-24T21:32:24.533 回答