mysql-造数据/列转行
创始人
2024-12-28 13:35:34
0

-- MySQL 列转行

set global group_concat_max_len=102400; set group_concat_max_len=102400; SELECT @@global.group_concat_max_len; SELECT @@group_concat_max_len; select table_name,concat(group_concat(COLUMN_NAME order by ORDINAL_POSITION separator ',')) as all_columns from information_schema.COLUMNS tb1 where table_schema='test' and table_name='table1' group by table_name;

使用方法:

mysql> set group_concat_max_len=102400; Query OK, 0 rows affected (0.00 sec)  mysql> SELECT @@global.group_concat_max_len; +-------------------------------+ | @@global.group_concat_max_len | +-------------------------------+ |                        102400 | +-------------------------------+ 1 row in set (0.00 sec)  mysql> SELECT @@group_concat_max_len; +------------------------+ | @@group_concat_max_len | +------------------------+ |                 102400 | +------------------------+ 1 row in set (0.00 sec)  mysql> select table_name,concat(group_concat(COLUMN_NAME order by ORDINAL_POSITION separator ',')) as all_columns     -> from information_schema.COLUMNS tb1     -> where table_schema='ccic_prod_mass1'     -> and table_name='t_pa_mass_policy_index'     -> group by table_name; +------------------------+------------------------------------------------------------------------------------------------------------------------------+ | table_name             | all_columns                                                                                                                  | +------------------------+------------------------------------------------------------------------------------------------------------------------------+ | t_pa_mass_policy_index | INDEX_RECORD_ID,BUSINESS_OBJECT_ID,INDEX_ID,POLICY_ID,FIELD_VALUE,DYNAMIC_FIELDS,INSERT_TIME,UPDATE_TIME,INSERT_BY,UPDATE_BY | +------------------------+------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)  mysql>    ##把去除自增列把本表数据重复插入本表 insert into  ccic_prod_mass1.t_pa_mass_policy_index(BUSINESS_OBJECT_ID,INDEX_ID,POLICY_ID,FIELD_VALUE,DYNAMIC_FIELDS,INSERT_TIME,UPDATE_TIME,INSERT_BY,UPDATE_BY) select BUSINESS_OBJECT_ID,INDEX_ID,POLICY_ID,FIELD_VALUE,DYNAMIC_FIELDS,INSERT_TIME,UPDATE_TIME,INSERT_BY,UPDATE_BY from ccic_prod_mass2.t_pa_mass_policy_index; 

 

相关内容

热门资讯

外挂阶段!werplan辅助软... 外挂阶段!werplan辅助软件,大菠萝免费辅助-竟然真的是有辅助攻略(哔哩哔哩)1、每一步都需要思...
随着!aapoker ai插件... 随着!aapoker ai插件(透视)总是真的有辅助工具(有挂透视)-哔哩哔哩运aapoker ai...
热门推荐!hhpoker可以控... 热门推荐!hhpoker可以控制吗,猎鱼达人破解版无限弹头,切实是真的有辅助插件(有挂秘籍)1、猎鱼...
透视玄学!werplan有挂吗... 透视玄学!werplan有挂吗(透视)总是是有辅助安装(有挂方式)-哔哩哔哩1)werplan有挂吗...
外挂大纲!哈糖大菠萝能开挂吗,... 外挂大纲!哈糖大菠萝能开挂吗,werplan外开挂-总是是有辅助软件(哔哩哔哩)1、每一步都需要思考...
玩家必备攻略!wepoker私... 玩家必备攻略!wepoker私人局透视方法,欢游互动辅助,总是是真的有辅助辅助(果真有挂)欢游互动辅...
出现新变化!xpoker辅助(... 出现新变化!xpoker辅助(透视)一直是真的辅助安装(有挂秘笈)-哔哩哔哩1、玩家可以在xpoke...
外挂绝活!菠萝德普辅助器免费版... 外挂绝活!菠萝德普辅助器免费版在哪里,约局吧德州真的有透视挂吗-一直一直总是有辅助教程(哔哩哔哩)菠...
一起来探讨!pokemmo辅助... 一起来探讨!pokemmo辅助脚本,丽水辅助器,切实真的有辅助辅助(有挂总结)pokemmo辅助脚本...
透视插件!德普之星私人局透视(... 透视插件!德普之星私人局透视(透视)确实真的是有辅助安装(有挂解密)-哔哩哔哩运德普之星私人局透视辅...