+----------------------------------+-------+---------------------+------+
| id | model | dates | who |
+----------------------------------+-------+---------------------+------+
| DB86A82A4D43AE94330F599281FF0A37 | 11111 | 2017-11-11 20:56:35 | A1 |
| F2B8467F36A00F7760BF142A6493EE71 | 11111 | 2017-11-11 20:56:56 | A2 |
| 4E3CBB3ACF5A7FB5580F447B87BB6AF0 | 11111 | 2017-11-11 20:57:17 | A3 |
+----------------------------------+-------+---------------------+------+
3 rows in set (0.00 sec)
mysql> select model,max(dates),who from unfinished where del!=1 and model='11111' order by `max(dates)` asc limit 100;
+-------+---------------------+------+
| model | max(dates) | who |
+-------+---------------------+------+
| 11111 | 2017-11-11 20:57:17 | A1 |
+-------+---------------------+------+
1 row in set (0.00 sec)
為什么列印出來who不是A3呢?
如何讓max或者min時,旁邊欄位一起關聯呢? 只有單獨max或者min時,就單獨取該段的值,旁邊的欄位根本不是關聯
新手請教,萬分感謝
uj5u.com熱心網友回復:
select unfi.* from unfinished unfi inner join (select model,max(dates) as max_dates from unfinished group by model desc) b ON unfi.model=b.model and unfi.dates=b.max_dates ;終于解決了。還有更效率的辦法嗎?
uj5u.com熱心網友回復:
參考下貼中的多種方法http://blog.csdn.net/acmain_chm/article/details/4126306
[征集]分組取最大N條記錄方法征集,及散分....
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/106499.html
標籤:MySQL
下一篇:三張表關聯,通過條件查詢
