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; 

 

相关内容

热门资讯

黑科技辅助!we-poker辅... 黑科技辅助!we-poker辅助软件演示,(wepoke好友房)先前真的是有挂,wpk教程(确实有挂...
发现一款!wepoker可以开... 【福星临门,好运相随】;发现一款!wepoker可以开透视,werplan外卦神器,揭秘教程(有挂攻...
盘点十款!红龙扑克辅助器(红龙... 盘点十款!红龙扑克辅助器(红龙扑克辅助器)往昔真的有挂(2026已更新)(哔哩哔哩),红龙扑克辅助器...
重磅来袭(WPK新版)wpk外... 重磅来袭(WPK新版)wpk外挂是真的还是假的(WpK)原生存在有挂(2020已更新)(哔哩哔哩)是...
黑科技辅助!wepoke软件透... 黑科技辅助!wepoke软件透明是真的,(Wepoke实测)往昔是真的有挂,攻略教程(有挂秘笈)-哔...
一起来探讨!德普辅助器可以用,... 一起来探讨!德普辅助器可以用,wepokerplus到底是挂了,透明教程(真实有挂)-哔哩哔哩相信很...
黑科技辅助(Wepoke存在)... 您好,Wepoke存在这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在...
重要通知!wepoke 软件(... 重要通知!wepoke 软件(WePoKe挂真的)从前有挂技术(2024已更新)(哔哩哔哩);AI辅...
黑科技辅助!扑克王辅助工具,(... 黑科技辅助!扑克王辅助工具,(扑克世界)都是是有挂,揭秘攻略(有挂存在)-哔哩哔哩;黑科技辅助!扑克...
实测发现!约局吧开挂神器是真的... 实测发现!约局吧开挂神器是真的,hhpoker有作弊辅助,力荐教程(有挂功能)-哔哩哔哩;1.约局吧...