0
我有一個表是這樣的:MySQL的選擇組合,並與最新的時間戳
+----+----+---------------------+---------------+
|lid |uid |timestamp |token |
|----+----+---------------------+---------------+
| 10 | 10 | 2014-02-03 12:17:18 | 52efcf118a0ba |
| 45 | 10 | 2014-02-03 12:51:13 | 52efd7046022d |
| 20 | 10 | 2014-02-04 03:47:59 | 52f0a931d3945 |
| 12 | 11 | 2014-02-04 05:21:57 | 52f0bf389371b |
| 34 | 11 | 2014-02-05 06:36:26 | 52f222384fe2d |
| 12 | 11 | 2014-02-05 07:06:42 | 52f229500b403 |
| 32 | 12 | 2014-02-04 05:21:57 | 52f0bf389371b |
| 55 | 12 | 2014-02-05 06:36:26 | 52f222384fe2d |
| 61 | 12 | 2014-02-05 07:06:42 | 52f229500b403 |
蓋和UID是外鍵和表不具有唯一列。
我想選擇分組的uid BUT與最新的時間戳。例如,從上面的數據,我只希望這些行:
+----+----+---------------------+---------------+
|lid |uid |timestamp |token |
|----+----+---------------------+---------------+
| 20 | 10 | 2014-02-04 03:47:59 | 52f0a931d3945 |
| 12 | 11 | 2014-02-05 07:06:42 | 52f229500b403 |
| 61 | 12 | 2014-02-05 07:06:42 | 52f229500b403 |
[爲每組分組結果獲取最多n條記錄]的可能重複(http://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-results ) –
謝謝。沒有注意到這一點。我認爲這對我有幫助。 –