我有一個mySQL數據庫來存儲自行車的位置信息。對於'最後位置'的方法,我只想得到自行車的最後一個入口,但是從所有的自行車。獲取最新條目組數據
例子:
ID | ## LAT ## | ## LNG ## | #### TIMESTAMP #### | BIKE_ID
----------------------------------------------------------
16 | N47.68526 | E16.59032 | 2015-01-12 14:49:51 | 3
17 | N47.36345 | E16.12096 | 2015-01-12 14:50:27 | 9
18 | N44.12526 | E15.12562 | 2015-01-12 14:51:45 | 1
19 | N47.87654 | E16.54323 | 2015-01-12 14:51:51 | 3
20 | N47.12345 | E16.12341 | 2015-01-12 14:52:27 | 1
21 | N47.12531 | E15.12561 | 2015-01-12 14:52:45 | 9
22 | N44.12531 | E16.12561 | 2015-01-12 14:53:01 | 1
23 | N47.12531 | E15.12561 | 2015-01-12 14:53:18 | 9
...
我想要的輸出,如:
ID | ## LAT ## | ## LNG ## | #### TIMESTAMP #### | BIKE_ID
----------------------------------------------------------
19 | N47.87654 | E16.54323 | 2015-01-12 14:51:51 | 3
22 | N44.12531 | E16.12561 | 2015-01-12 14:53:01 | 1
23 | N47.12531 | E15.12561 | 2015-01-12 14:53:18 | 9
檢查[此答案](http://stackoverflow.com/questions/27183964/sql-sorting-does-not-follow-group-by-statement-always-uses-primary-key/27184343#27184343), [this one](http://stackoverflow.com/questions/27801243/how-to-select-a-row-with-maximum-value-for-a-column-in-mysql/27801835#27801835),[this一個](http://stackoverflow.com/questions/27036210/sql-select-first-column-and-for-each-row-select-unique-id-and-the-last-date/27036920#27036920)和[this one](http://stackoverflow.com/questions/612231/how-can-i-select-rows-with-maxcolumn-value-distinct-by-another-column-in-sql/27802817#27802817)。 – axiac
我敢打賭,這是關於SO的最常問的MySQL問題。 – axiac
[檢索每個組中的最後一條記錄]的可能的重複(http://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group) –