为了账号安全,请及时绑定邮箱和手机立即绑定

laravel 去重问题

laravel 去重问题

PHP
慕盖茨4494581 2019-03-07 09:09:11
$coupon->whereIn('id',$res1['coupon_id'])->where('status',2)->get(); //怎么根据merchant_id 来去重 我尝试了 $coupon->whereIn('id',$res1['coupon_id'])->where('status',2)->groupBy('merchant_id')->get(); 结果是SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'run.pq_coupon.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select * from pq_coupon where pq_coupon.deleted_at is null group by merchant_id)
查看完整描述

8 回答

?
RISEBY

TA贡献1856条经验 获得超5个赞

编辑 config/database.php 第53行 strict的值改成false,我的是5.5的在53行,你看下你的在第几行,['connections']['mysql']['strict'], 路径是这样的

查看完整回答
反对 回复 2019-03-18
?
慕婉清6462132

TA贡献1804条经验 获得超2个赞

如果groupBy不行的话, distict 又该如何书写代码?

查看完整回答
反对 回复 2019-03-18
?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

use DB;

$coupon->select(DB::Raw('DISTINCT(merchant_id)')->whereIn('id',$res1['coupon_id'])->->where('status',2)->get();

查看完整回答
反对 回复 2019-03-18
?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

groupby放在get后面

查看完整回答
反对 回复 2019-03-18
?
MYYA

TA贡献1868条经验 获得超4个赞

找到 config/database.php 文件中的 connections -> mysql ;
strict 改为 false ;

具体可以参考 最适合入门的Laravel初级教程(六)

如果你想 知其所以然 ;
我给你个关键字 only_full_group_by ;
百之谷之必应之;
搜索一遍你就懂了;

查看完整回答
反对 回复 2019-03-18
?
Cats萌萌

TA贡献1805条经验 获得超9个赞

楼主可以这样去重, Goods::get()->groupBy('userid');

查看完整回答
反对 回复 2019-03-18
  • 8 回答
  • 0 关注
  • 1842 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号