1.以id分组,把name字段的值打印在一行,逗号分隔(默认)
select id,group_concat(name) from aa group by id;
2.多表多行多列合并。
SELECT cg.`ID`,cg.`Name`,cg.`Notes`,cg.`AddDate`,GROUP_CONCAT(cgm.`CategoryID` )
FROM PR_GDS.`CategoryGroups` cg LEFT JOIN PR_GDS.`CategoryGroupMapping` cgm ON cg.`ID`=cgm.`GroupID`
WHERE cg.`ID`=401
GROUP BY cg.`ID`;
Mysql的查询结果列字段拼接,可以用下面两个函数实现:
1. concat函数
select CONCAT(`AttributeId`,`NAME`) FROM `CategoryMapping`;