0

我在 MySql 数据库中有一个日志,现在我会用它来检查会话,所以我想获取“类型 3”之前的所有行而不是更多。

+--------+-------------+---------------------+-----------+---------+------+
| id     | username    | date                | address   | success | type |
+--------+-------------+---------------------+-----------+---------+------+
| 110771 | test        | 2013-08-02 11:17:54 | 127.0.0.1 |       1 |    5 |
| 110772 | test        | 2013-08-02 11:18:03 | 127.0.0.1 |       1 |    3 |
| 110773 | test        | 2013-08-02 11:18:13 | 127.0.0.1 |       1 |    7 |
| 110774 | test        | 2013-08-02 11:18:17 | 127.0.0.1 |       1 |    5 |
+--------+-------------+---------------------+-----------+---------+------+

我怎样才能做到这一点 ?

4

1 回答 1

2

这是一种方法:

SELECT *
FROM logTable a
WHERE NOT EXISTS
(
    SELECT 1
    FROM logTable b
    WHERE b.date <= a.date
    AND b.type = 3
)
于 2013-08-02T09:28:04.833 回答