Laravel通过未获取所有记录来查询Buider组 [英] Laravel Query Buider Group By Not Getting All The Records

查看:70
本文介绍了Laravel通过未获取所有记录来查询Buider组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆