mysql字符段连接

* concat中有一个参数为NULL,查出来的就为NULL

1、CONCAT(str1,str2,...)

select CONCAT(eid,':',ename) from t_employee;

 

 

 

 

2、CONCAT_WS(separator,str1,str2,...)

select CONCAT_WS(',',eid,ename) from t_employee;

 

 

3、GROUP_CONCAT(expr)

格式:group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])

select dept_id,GROUP_CONCAT(DISTINCT ename ORDER BY eid desc SEPARATOR ';') from t_employee GROUP BY dept_id;

 

posted @ 2020-10-23 10:32  6969  阅读(76)  评论(0)    收藏  举报