使用 group by 和 Laravel 获取最新行
本文介绍了使用 group by 和 Laravel 获取最新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使有多个这样的问题,我也无法让我的查询返回具有最近日期的行和 group by.
Even though there are multiple questions like this I can't get my query to return the row with the most recent date with a group by.
我有下表..
我正在尝试获取最新日期的行.
and I'm tryin to get the rows with most recent date.
目前此查询返回最近日期的行.
Currently this query returns the rows with the last recent date.
推荐答案
问题是结果集会先分组然后有序.您可以使用嵌套选择来获取您想要的内容.
The problem is that the result set will be first grouped then ordered. You can use nested select to get what you want.
SQL 查询:
使用 Laravel:
With Laravel:
您只需要添加您的 where()
子句.
You just need to add your where()
clauses.
这篇关于使用 group by 和 Laravel 获取最新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!