发布网友 发布时间:2022-04-30 04:37
共3个回答
懂视网 时间:2022-04-30 08:59
;*************************** 1. row ***************************
TBL_ID: 6
CREATE_TIME: 1437309077
LAST_ACCESS_TIME: 0
TBL_NAME: students
TBL_TYPE: MANAGED_TABLE
*************************** 2. row ***************************
TBL_ID: 11
CREATE_TIME: 1437402612
LAST_ACCESS_TIME: 0
TBL_NAME: user_info_bucketed_1
TBL_TYPE: MANAGED_TABLE
2 rows in set (0.00 sec)
mysql> select * from user_info;
+---------+-----------+-----------+
| user_id | firstname | lastname |
+---------+-----------+-----------+
| 100 | Hadoop | Spark01 |
| 100 | Hadoop | Spark02 |
| 100 | Hadoop | Spark03 |
| 200 | Hive | Python2.6 |
| 200 | Hive | Python2.7 |
| 200 | Hive | Python3.3 |
| 200 | Hive | Python3.4 |
| 300 | HBase | Pig |
| 300 | HBase | Zoo |
+---------+-----------+-----------+
9 rows in set (0.00 sec)
mysql> select user_id,group_concat(firstname) from user_info group by user_id;
+---------+-------------------------+
| user_id | group_concat(firstname) |
+---------+-------------------------+
| 100 | Hadoop,Hadoop,Hadoop |
| 200 | Hive,Hive,Hive,Hive |
| 300 | HBase,HBase |
+---------+-------------------------+
3 rows in set (0.06 sec)
mysql> select user_id,group_concat(lastname) from user_info group by user_id;
+---------+-----------------------------------------+
| user_id | group_concat(lastname) |
+---------+-----------------------------------------+
| 100 | Spark01,Spark02,Spark03 |
| 200 | Python2.6,Python2.7,Python3.3,Python3.4 |
| 300 | Pig,Zoo |
+---------+-----------------------------------------+
3 rows in set (0.00 sec)
mysql> select user_id,group_concat(lastname separator ‘;‘) from user_info group by user_id;
+---------+-----------------------------------------+
| user_id | group_concat(lastname separator ‘;‘) |
+---------+-----------------------------------------+
| 100 | Spark01;Spark02;Spark03 |
| 200 | Python2.6;Python2.7;Python3.3;Python3.4 |
| 300 | Pig;Zoo |
+---------+-----------------------------------------+
3 rows in set (0.00 sec)
mysql> select user_id,group_concat(lastname order by lastname desc separator ‘#‘) from user_info group by user_id;
+---------+-------------------------------------------------------------+
| user_id | group_concat(lastname order by lastname desc separator ‘#‘) |
+---------+-------------------------------------------------------------+
| 100 | Spark03#Spark02#Spark01 |
| 200 | Python3.4#Python3.3#Python2.7#Python2.6 |
| 300 | Zoo#Pig |
+---------+-------------------------------------------------------------+
3 rows in set (0.00 sec)
MySQL行列转换拼接
标签:
热心网友 时间:2022-04-30 06:07
group_contact刚好满足你的这个要求哦热心网友 时间:2022-04-30 07:25
阳光上的桥 被坑了,我就查了半天这个函数。
楼主的group_contact 写错了!! 应该是group_concat
id name
1 a
1 b
1 c