我有一个红移表,记录如下
+====+======+=========+============+
| Id | Book | Action | Timestamp |
+====+======+=========+============+
| 1 | ABC | ADDED | 1111111111 |
+----+------+---------+------------+
| 1 | ABC | REMOVED | 2222222222 |
+----+------+---------+------------+
| 1 | ABC | CHECKED | 3333333333 |
+----+------+---------+------------+
| 2 | XYZ | ADDED | 4444444444 |
+----+------+---------+------------+
| 2 | XYZ | CHECKED | 5555555555 |
+----+------+---------+------------+
| 5 | DEF | CHECKED | 6666666666 |
+----+------+---------+------------+
| 5 | DEF | CHECKED | 7777777777 |
+====+======+=========+============+
我想要的是为每本书获取单一记录。在重复的情况下,按 CHECKED 的最低等级的动作进行优先级排序,其余所有动作将具有相同的优先级,然后选择最近的记录。
预期产出
+====+======+=========+============+
| Id | Book | Action | Timestamp |
+====+======+=========+============+
| 1 | ABC | REMOVED | 2222222222 |
+----+------+---------+------------+
| 2 | XYZ | ADDED | 4444444444 |
+----+------+---------+------------+
| 5 | DEF | CHECKED | 7777777777 |
+====+======+=========+============+