mysql 一对多 合并多个通过 逗号拼接展示

mysql 一对多 合并多个通过 逗号拼接展示

以上内容由chatgpt中文网 动态生成

SELECT
    user_id,
    project_id,
    GROUP_CONCAT(project_specs_id) AS merged_specs_ids
FROM
    zt_medication_specs_total
WHERE
    specs_num_total < 5
GROUP BY
    user_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();
    }

你可能感兴趣的:(sql,laravel)