2022-01-25|閱讀時間 ‧ 約 1 分鐘

Laravel get row with the max of a column, group by some cols

如上圖資料,想要group by g_id找到最大update_datetime的row:
XXX::whereRaw('update_datetime in (select max(update_datetime) from xxx GROUP BY (g_id))')
->get();
分享至
成為作者繼續創作的動力吧!
小弟是一位軟體工程師,樂於幫助他人,撰寫技術文章除了幫助自己複習以外,也希望可以幫助到他人,若文章內容有誤,還請大大不吝給予指教!
從 Google News 追蹤更多 vocus 的最新精選內容從 Google News 追蹤更多 vocus 的最新精選內容

發表回應

成為會員 後即可發表留言