$goods_id = 34;
//商品sku规格值表
//关联规格表取规格名
//关联规格值表取规格值
$spec_res = $this->specIndexModel
->select('goods_spec_index.spec_id','goods_spec_index.spec_value_id',
'goods_spec.spec_title','goods_spec_values.spec_value')
->join('goods_spec','goods_spec.spec_id','=','goods_spec_index.spec_id')
->join('goods_spec_values','goods_spec_values.spec_value_id','=','goods_spec_index.spec_value_id')
->whereRaw("goods_id = {$goods_id}")
->orderBy('goods_spec.spec_id','desc')
->groupBy('goods_spec_index.spec_id','goods_spec_index.spec_value_id')
->get()
->toArray();
报错如下:
image.png
解决方法:config下database.php里strict改成false
// 'strict' => true,
'strict' => false,//改成false解决groupBy报错问题
未分组情况下,重复数据
image.png
groupBy('goods_spec_index.spec_id') //只按规格名的id分组
image.png
groupBy('goods_spec_index.spec_id') //只按规格值的id分组
image.png
groupBy('goods_spec_index.spec_id','goods_spec_index.spec_value_id')//按规格名和值的id一起分组
image.png