日期:2014-05-16  浏览次数:20756 次

mysql多数据合并成一条,

求答案,
如果看不清,也可点此处:http://zhidao.baidu.com/question/427405338.html#reply-box-1041188895

------解决方案--------------------
SELECT a.`name`,MAX(a.`codel`) ,MAX(a.`code2`),MAX(a.`code3`)FROM biao21 a LEFT JOIN biao21 b ON a.`name`=b.`name` AND 
((a.`codel` IS NOT NULL AND a.`codel`<>b.`codel` 
OR
a.`code2` IS NOT NULL AND a.`code2`<>b.`code2`
OR
a.`code3` IS NOT NULL AND a.`code3`<>b.`code3`
)

AND a.`id`>b.`id`) WHERE b.`id` IS NOT NULL
GROUP BY a.`name`