SELECt m.id, m.date_time, m.foreign_key, m.key, m.value
FROM MyTable m
LEFT OUTER JOIN MyTable mm
ON (m.foreign_key = mm.foreign_key
AND m.key = mm.key
AND m.date_time < mm.date_time)
WHERe mm.key IS NULL
AND m.foreign_key=4;
给了我我所需要的。即:
+----+---------------------+-------------+-------------+-------+| id | date_time| foreign_key | key | value |+----+---------------------+-------------+-------------+-------+| 9 | 2010-01-01 00:00:08 |4 | humidity | 35 || 17 | 2010-01-01 00:00:16 |4 | temperature | 19 || 18 | 2010-01-01 00:00:17 |4 | dew_point | 24 |+----+---------------------+-------------+-------------+-------+
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)