【发布时间】:2018-08-02 10:12:04
【问题描述】:
我知道使用 max 有很多问题。但是看起来我不知道如何查询
我想根据哈希组查询最近完成的记录。
表值:
hash|method_name |event_name|end_time
123 |方法1 |事件1 | 2018-07-28 02:16:28
123 |方法2 |事件2 | 2018-07-28 02:17:28
123 |方法3 |事件3 | 2018-07-28 02:18:28
456 |方法2 |事件1 | 2018-07-28 02:18:00
678 |方法2 |事件1 | 2018-07-28 02:20:00
156 |方法1 |事件1 | 2018-07-28 02:10:28
156 |方法2 |事件2 | 2018-07-28 02:11:29
156 |方法3 |事件3 | 2018-07-28 02:12:30
963 |方法3 |事件3 | 2018-07-28 02:16:30
103 |方法3 |事件3 | 2018-07-28 02:15:30
结果:
hash|method_name |event_name|end_time
123 |方法1 |事件1 | 2018-07-28 02:16:28
123 |方法2 |事件2 | 2018-07-28 02:17:28
123 |方法3 |事件3 | 2018-07-28 02:18:28
678 |方法2 |事件1 | 2018-07-28 02:20:00
963 |方法3 |事件3 | 2018-07-28 02:16:30
解决了我的问题的查询。
select * from table_name where hash in (select hash from table_name group by method_name having max(end_time));
【问题讨论】:
-
基于上表值。我想查询下面提到的结果。对不起,我是 mysql 复杂查询的新手。
-
“完成记录”是什么意思?
-
添加您当前的查询及其结果
-
无论 end_time 设置在哪里,我都认为它是一个已完成的事件。如果没有在执行中发送它。
-
基本上我想要特定 method_name 和 event_name 组的最后更新记录。除非它出现在具有多个事件的其他哈希组中,否则不应出现重复值。
标签: mysql