Laravel通过未获取所有记录来查询Buider组 [英] Laravel Query Buider Group By Not Getting All The Records
问题描述
我正在尝试使用transaction
表中type
字段上的groupBy
获取数据.我正在使用此查询
I am trying to get the data using groupBy
on type
field from my transaction
table. I am using this query
DB::table($this->table)
->select()
->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
->groupBy('type')
->get();
但是它没有给出complete records
.我的表中有10多个记录.但这只给了我两个.一个用于类型= 1,另一个用于类型= 2.它只是从每种类型的记录中选择.我期望我将基于two result set
中分组的condition
获取所有的transactions
.有人知道为什么会这样吗?
But it is not giving the complete records
. There are more than 10 records in my table. But it is giving me only two. One for type=1 and another for type=2. It is selecting only on record from each type. I am expecting that i will get all the transactions
based on condition
grouped in two result set
. Anyone know why it is happening?
推荐答案
尝试改为调用Collection
groupBy.只需将groupBy放在get()之后.应该可以.
Try to call Collection
groupBy instead. Just put groupBy after get(). It should work.
DB::table($this->table)
->select()
->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
->get()
->groupBy('type');
这篇关于Laravel通过未获取所有记录来查询Buider组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!