Laravel Query Builder Group未获得所有记录

问题描述 投票:1回答:2

我想从我的groupBy表中使用type字段上的transaction获取数据。我正在使用此查询

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

但它没有给complete records。我的表中有超过10条记录。但它只给了我两个。一个用于type = 1,另一个用于type = 2。它只选择每种类型的记录。我期待我将获得所有基于transactionsconditiontwo result set。有人知道为什么会这样吗?

php mysql laravel laravel-5 group-by
2个回答
1
投票

试着改为调用Collection groupBy。只需在get()之后放入groupBy。它应该工作。

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

0
投票

常见问题解答::这里( '型', '主机') - >得到() - > GROUPBY( '类');

© www.soinside.com 2019 - 2024. All rights reserved.