mysql 一对多 合并多个通过 逗号拼接展示
以上内容由chatgpt中文网 动态生成
SELECTuser_id,project_id,GROUP_CONCAT(project_specs_id) AS merged_specs_ids
FROMzt_medication_specs_total
WHEREspecs_num_total < 5
GROUP BYuser_id, project_id;
laravel model 对应写法
return $this->select('user_id', 'project_id')->selectRaw('GROUP_CONCAT(project_specs_id) AS merged_specs_ids')->where('specs_num_total', '<', 5)->groupBy('user_id', 'project_id')->get();}