关于 ORM 模型关联分组的问题

$search = Search::with(['brand'=>function($query){

//以上代码就是分组的代码.然后筛选出需要的字段

报错信息

SQLSTATE[42000]: Syntax error or access violation: 1055 'smart360.sm_search.id' isn't in GROUP BY (SQL: select count(brand_id) as num, id, brand_id, part_num from sm_search group by brand_id, part_num having brand_id > 0 and part_num != 0 order by num desc)

//上面的代码就是根据brand_id和part_num分组,然后统计最多的.倒序排序;上面的sql使用命令行执行是没错的

Sql语句

select count(brand_id) as num, id, brand_id, part_num from sm_search group by brand_id, part_num having brand_id > 0 and part_num != 0 order by num desc

kenuo
修改的评论也不能少于六个字哦!