mysql的group concat函式使用示例

2022-10-06 01:51:10 字數 624 閱讀 5430

my程式設計客棧sql中group_concat函式,完整的語法如下:

複製** **如下:

group_concat([distinct] 要連線的字段 [order by asc/desc 排序字段] [separator '分隔符'])

基本查詢

複製** **如下:

select * from aa;

複製** **如下:

+------+------+

| id| name |

+-程式設計客棧-----+------+

|1 | 10|

|1 | 20|

|1 程式設計客棧| 20|

|2 | 20|

|3 | 200 |

|www.cppcns.com3 | 500 |

+------+------+

6 rows in set (0.00 sec)

以id分組,把name欄位的值列印在一行,逗號分隔(程式設計客棧預設)

複製** **如下:

select id,group_concat(name) from aa group by id;

本文標題: mysql的group_concat函式使用示例

本文位址:

Mysql分組資料合併group concat用法

group concat用法 預設用法 select group concat vaccine name as do accinename from t vaccine where id in select vaccine id from t dog vaccine where dog id 1 1...

MySQL 多行資料合併 GROUP CONCAT

表結構及資料 drop table if exists course create table course id int 11 not null,name varchar 50 default null comment 姓名 course name varchar 50 default null ...

MySQL 多行資料合併 GROUP CONCAT

表結構及資料 drop table if exists course create table course name varchar 255 character set utf8 collate utf8 general ci default null,course name varchar 25...