$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
fromsm_search
group bybrand_id
,part_num
havingbrand_id
> 0 andpart_num
!= 0 order bynum
desc)
//上面的代码就是根据brand_id和part_num分组,然后统计最多的.倒序排序;上面的sql使用命令行执行是没错的
Sql语句
select count(brand_id) as num,
id
,brand_id
,part_num
fromsm_search
group bybrand_id
,part_num
havingbrand_id
> 0 andpart_num
!= 0 order bynum
desc