如何在找到某个字段值之前从表中获取最后(谈论日期时间)记录?
如果我有这张桌子:
+----+---------------------+-------+-----------+
| id | date | flag | data |
+----+---------------------+-------------------+
| 1 | 2008-09-01 15:02:00 | 1 | .... . |
| 2 | 2008-09-01 16:15:00 | 5 | .... . |
| 3 | 2008-09-01 16:19:00 | 4 | .... . |
| 4 | 2008-09-01 16:20:00 | 4 | .... . |
| 5 | 2008-09-01 16:20:00 | 5 | .... . |
| 6 | 2008-09-01 18:18:00 | 9 | .... . |
+----+---------------------+-------+-----------+
我想在找到“4”标志字段值之前获取最后的记录,我的意思是:
SELECT * FROM mytable WHERE..... ORDER BY id DESC
+----+---------------------+-------+-----------+
| id | date | flag | data |
+----+---------------------+-------------------+
| 5 | 2008-09-01 18:18:00 | 9 | .... . |
| 4 | 2008-09-01 16:20:00 | 5 | .... . |
+----+---------------------+-------+-----------+
我怎么才能得到它?
补充:另外我会知道如何获取包含第一次出现“4”的记录
补充:标志字段没有有序值
谢谢