如上圖資料,想要group by g_id找到最大update_datetime的row: XXX::whereRaw('update_datetime in (select max(update_datetime) from xxx GROUP BY (g_id))')->get(); 本筆記參考:1. https://laravelquestions.com/2021/03/29/get-maximum-value-containing-row-using-groupby-function-in-laravel/