mysql 拼接列数据

SELECT IF(@ids=w.contract_id,@num:=@num,@num:=@num+1) AS num,@ids:=w.contract_id,w.* FROM

(SELECT (SELECT GROUP_CONCAT(project_name)
FROM production_income_data WHERE contract_id = a.contract_id) AS `names`,

(SELECT GROUP_CONCAT(project_code) FROM production_income_data
WHERE contract_id = a.contract_id) AS `codes`, a.*FROM production_income_data a )w

,(SELECT @num:=0) u,(SELECT @ids:='') m ORDER BY w.contract_id

 

posted on 2019-07-02 18:04  江清澜静  阅读(2295)  评论(0编辑  收藏  举报

导航