Laravel Eloquent - distinct() 和 count() 不能正常工作 [英] Laravel Eloquent - distinct() and count() not working properly together
本文介绍了Laravel Eloquent - distinct() 和 count() 不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我试图获取查询中不同 pid 的数量,但返回的值是错误的.
So I'm trying to get the number of distinct pids on a query, but the returned value is wrong.
这就是我尝试做的:
$ad->getcodes()->groupby('pid')->distinct()->count()
什么返回值2",而它应该返回的值应该是1".
what returns the value "2", while the value it should return, should be "1".
作为一种解决方法,我正在这样做:
As a workaround, I'm doing this:
count($ad->getcodes()->groupby('pid')->distinct()->get())
什么工作正常并返回1"
what works fine and returns "1"
是否有任何规则不能在同一个查询中使用 count 和 distinct ?我发现解决方法有点重",我想让原始查询正常工作:(
Is there any rule where count and distinct cannot be on the same query? I find the workaround kind of "heavy", I would like to make the original query work :(
推荐答案
以下应该有效
$ad->getcodes()->distinct()->count('pid');
这篇关于Laravel Eloquent - distinct() 和 count() 不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文