举例:有t_person表如下:

 

一、mysql行拼接:

拼接某一行:

无分隔符:select   CONCAT(id,idcard,`status`,content)   from  t_person    

有分隔符:select   CONCAT_WS(',',id,idcard,`status`,content)   from  t_person 

二、列拼接,最实用的功能是快速取一个大表的所有列名。

SELECT   GROUP_CONCAT(COLUMN_NAME SEPARATOR ',')  FROM information_schema.`COLUMNS`  WHERE TABLE_NAME = 't_person'   group by TABLE_NAME

Logo

更多推荐