mysql之group_concat函数详解
来源:互联网 发布:电子族谱软件 编辑:程序博客网 时间:2024/06/07 23:16
函数语法:
group_concat( [DISTINCT] 要连接的字段 [Order BY 排序字段 ASC/DESC] [Separator ‘分隔符’] )
下面举例说明:
select * from goods;
+——+——+
| id| price|
+——+——+
|1 | 10|
|1 | 20|
|1 | 20|
|2 | 20|
|3 | 200 |
|3 | 500 |
+——+——+
6 rows in set (0.00 sec)
以id分组,把price字段的值在同一行打印出来,逗号分隔(默认)
select id, group_concat(price) from goods group by id;
+——+——————–+
| id| group_concat(price) |
+——+——————–+
|1 | 10,20,20|
|2 | 20 |
|3 | 200,500|
+——+——————–+
3 rows in set (0.00 sec)
以id分组,把price字段的值在一行打印出来,分号分隔
select id,group_concat(price separator ‘;’) from goods group by id;
+——+———————————-+
| id| group_concat(price separator ‘;’) |
+——+———————————-+
|1 | 10;20;20 |
|2 | 20|
|3 | 200;500 |
+——+———————————-+
3 rows in set (0.00 sec)
以id分组,把去除重复冗余的price字段的值打印在一行,逗号分隔
select id,group_concat(distinct price) from goods group by id;
+——+—————————–+
| id| group_concat(distinct price) |
+——+—————————–+
|1 | 10,20|
|2 | 20 |
|3 | 200,500 |
+——+—————————–+
3 rows in set (0.00 sec)
以id分组,把price字段的值打印在一行,逗号分隔,按照price倒序排列
select id,group_concat(price order by price desc) from goods group by id;
+——+—————————————+
| id| group_concat(price order by price desc) |
+——+—————————————+
|1 | 20,20,10 |
|2 | 20|
|3 | 500,200|
+——+—————————————+
3 rows in set (0.00 sec)
- mysql之group_concat函数详解
- Mysql 函数 Group_concat()详解
- MySQL中group_concat函数详解
- MySQL 的 GROUP_CONCAT 函数详解
- mysql group_concat函数和concat_ws 函数 详解
- mysql函数之——GROUP_CONCAT
- mysql之group_concat函数详解:将相同的行组合起来
- MySQL之SQL函数-1 MySQL中group_concat函数
- MySQL中group_concat函数
- MySQL中group_concat函数
- mysql的group_concat函数
- 关于mysql函数GROUP_CONCAT
- MySQL group_concat函数
- MySQL中group_concat函数
- MySQL中group_concat函数
- 关于mysql函数GROUP_CONCAT
- 关于mysql函数GROUP_CONCAT
- MySQL中group_concat函数
- 子div没撑起父div高度
- jq移动端日历签到
- Deep Learning 8.1-8.2笔记
- android 解决ScrollView中的子布局不能够填充整个ScrollView
- spring学习笔记 -- day14 基于注解的整合
- mysql之group_concat函数详解
- linux的GCC常用口令
- web前端全面技能图谱
- 194. Transpose File
- BSDF
- #pragma pack(push,1)与#pragma pack(1)的区别
- 每日积累(20170820-day-26)(libEGL.so & -lopencv_dep_cudart bug)
- STORM入门之(Topology简易Demo)
- SQL查询部分数据表中部分数据