laravel通过不获取所有记录来查询buider组

bvjxkvbb  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(255)

我正在尝试使用 groupBytype 从我的 transaction table。我正在使用此查询

DB::table($this->table)
    ->select()
    ->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
    ->groupBy('type')
    ->get();

但它并没有给予 complete records . 我的table上有10多条记录。但它只给了我两个。一个用于类型=1,另一个用于类型=2。它只从每种类型的记录中选择。我希望我能拿到所有的钱 transactions 基于 condition 分组在 two result set . 有人知道为什么会这样吗?

nkhmeac6

nkhmeac61#

试着打电话 Collection 改为groupby。只需将groupby放在get()之后。应该有用。

DB::table($this->table)
    ->select()
    ->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
    ->get()
    ->groupBy('type');
cnwbcb6i

cnwbcb6i2#

常见问题解答::where('type','host')->get()->groupby('category');

相关问题