特定值后无行
No Rows after a specific value
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的计数,其中action列中的最后一条记录(日期时间按升序排列)应该只支持一次,并且每个ID都支持之后应该没有记录
在上面table中只有记录 ID 的 106 和 104 在操作列中只支持一次并且在按日期时间排序支持后没有记录所以我需要计数(2)/显示 104 和106 ..
有人可以帮忙吗!!..
嗯。一种方法使用聚合和 having
:
select recordid
from t
group by recordid
having min(case when action = 'Support' then datetime end) = max(datetime);
这实际上是说第一次看到 "Support" 是 recordid
的最晚时间。
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的计数,其中action列中的最后一条记录(日期时间按升序排列)应该只支持一次,并且每个ID都支持之后应该没有记录
在上面table中只有记录 ID 的 106 和 104 在操作列中只支持一次并且在按日期时间排序支持后没有记录所以我需要计数(2)/显示 104 和106 ..
有人可以帮忙吗!!..
嗯。一种方法使用聚合和 having
:
select recordid
from t
group by recordid
having min(case when action = 'Support' then datetime end) = max(datetime);
这实际上是说第一次看到 "Support" 是 recordid
的最晚时间。