问题
What's the best way to perform a groupwise maximum using Laravel's Eloquent ORM such that it returns instances of models?
回答1:
Based on this stackoverflow answer, I was able to create the following:
$query = MyModel
::from(DB::raw(
'my_models NATURAL JOIN (
SELECT user_id, MAX(created_at) created_at
FROM my_models
GROUP BY user_id
) t'
))
;
来源:https://stackoverflow.com/questions/17043309/performing-a-groupwise-maximum-in-laravel-4