$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'], 路径是这样的
陪伴而非守候
TA贡献1757条经验 获得超8个赞
use DB;
$coupon->select(DB::Raw('DISTINCT(merchant_id)')->whereIn('id',$res1['coupon_id'])->->where('status',2)->get();
MYYA
TA贡献1868条经验 获得超4个赞
找到 config/database.php 文件中的 connections -> mysql ;
把 strict 改为 false ;
具体可以参考 最适合入门的Laravel初级教程(六)
如果你想 知其所以然 ;
我给你个关键字 only_full_group_by ;
百之谷之必应之;
搜索一遍你就懂了;
- 8 回答
- 0 关注
- 1842 浏览
添加回答
举报
0/150
提交
取消
