MySQL行列轉換拼接

來源:互聯網
上載者:User

標籤:

mysql> select TBL_ID,CREATE_TIME,LAST_ACCESS_TIME,TBL_NAME,TBL_TYPE from TBLS;

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

| TBL_ID | CREATE_TIME | LAST_ACCESS_TIME | TBL_NAME             | TBL_TYPE      |

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

|      6 |  1437309077 |                0 | students             | MANAGED_TABLE |

|     11 |  1437402612 |                0 | user_info_bucketed_1 | MANAGED_TABLE |

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

2 rows in set (0.00 sec)

 

mysql> select TBL_ID,CREATE_TIME,LAST_ACCESS_TIME,TBL_NAME,TBL_TYPE from TBLS \G;

*************************** 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行列轉換拼接

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.