我想獲取sql中每個日期時間字段的最新數據。任何人都可以幫我解決這個問題。 這是我的表格結構。如何根據mysql中的日期時間字段獲取最新數據?
| ID | USER | TIME |
-------------------------------------
| 2 | abc | 2009-01-01 01:00:00 |
| 3 | abc | 2009-01-01 22:00:00 |
| 5 | abc | 2009-01-01 10:00:00 |
| 6 | xyz | 2009-01-02 01:00:00 |
| 7 | xyz | 2009-01-02 22:00:00 |
| 8 | xyz | 2009-01-02 10:00:00 |
而我想這樣的輸出。
| ID | USER | TIME |
-------------------------------------
| 3 | abc | 2009-01-01 22:00:00 |
| 7 | xyz | 2009-01-02 22:00:00 |
編輯:需求變化。正如我所說的,我希望每個用戶的每個日期的最新記錄。
| ID | USER | TIME |
-------------------------------------
| 2 | abc | 2009-01-01 01:00:00 |
| 3 | abc | 2009-01-01 22:00:00 |
| 5 | abc | 2009-01-01 10:00:00 |
| 6 | xyz | 2009-01-01 01:00:00 |
| 7 | xyz | 2009-01-01 22:00:00 |
| 8 | xyz | 2009-01-01 10:00:00 |
| 10 | abc | 2009-01-04 09:00:00 |
| 11 | abc | 2009-01-04 02:00:00 |
| 15 | xyz | 2009-01-04 04:00:00 |
| 25 | xyz | 2009-01-04 06:00:00 |
而我想這樣的輸出。
| ID | USER | TIME |
-------------------------------------
| 3 | abc | 2009-01-01 22:00:00 |
| 7 | xyz | 2009-01-01 22:00:00 |
| 10 | abc | 2009-01-04 09:00:00 |
| 25 | xyz | 2009-01-04 06:00:00 |
先清楚你的要求,然後發佈你到目前爲止所嘗試的內容..我們不是在這裏爲你做代碼。 –