现在的位置: 首页 > 综合 > 正文

SQL+合并多个记录group_concat()、wmsys.wm_concat()

2018年05月21日 ⁄ 综合 ⁄ 共 520字 ⁄ 字号 评论关闭

mysql> select * from tab1;

+----+------+
| id | c2   |
+----+------+
|  1 |    1 |
|  2 |    1 |
|  3 |    1 |
|  4 |    1 |
|  5 |    2 |
|  6 |    2 |
+----+------+
6 rows in set (0.00 sec)
mysql> select c2,group_concat(id order by id separator ',') from tab1 group by c
2;
+------+--------------------------------------------+
| c2   | group_concat(id order by id separator ',') |
+------+--------------------------------------------+
|    1 | 1,2,3,4                                    |
|    2 | 5,6                                        |
+------+--------------------------------------------+
2 rows in set (0.00 sec)

ORACLE也有这样的一个函数  wmsys.wm_concat()

抱歉!评论已关闭.