mysql 分組取最新一條

2021-10-14 11:21:07 字數 366 閱讀 7490

mysql 分組取最新一條

select *

from (select *

from usr_warn_info_handle

order by handle_time desc

limit 10) t

group by warn_info_id

usr_warn_info_handle 表名 

handle_time  時間 

warn_info_id 分組字段

說明: 從mysql5.7開始,子查詢的排序已經變為無效了。所以要加個limit,這樣子查詢就不光是排序,所以此時排序會生效,但有條數限制10000

參考位址 : 

Mysql 分組取最新一條

我有如下這張表的資料,需要根據mobile 號碼分組,每條 取最新的資料 方案1 select from select from model online forecastscore phone0001 order by id desc as cn group by cn.mobile 方案2 最佳...

sql 取最新一條記錄

1.選出某個條件最新的一條記錄 選出最新狀態下的每乙個單號對應的子單資料 select distinct a.receiving code,a.product barcode,a.rd putaway qty from odoo ykd oversea shipping information a ...

mysql 分組查詢每組的最新一條資料

1.原始資料 學生成績表 2.想要獲取每個考生最新的考試成績,網上的例子 select a.from select from scoreinfo order by scoreinfo.createtime desc as a group by a.snum order by a.createtime...