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; 

 

相关内容

热门资讯

必备透视!hhpoker到底可... 必备透视!hhpoker到底可以作弊吗,微乐钻石兑换码,法门教程(真是有挂)-哔哩哔哩1、hhpok...
解谜透视!poker红龙辅助!... 解谜透视!poker红龙辅助!一直一直都是有辅助神器(有挂规律)-哔哩哔哩1、下载好poker红龙辅...
必备透视!德州hhpoker脚... 必备透视!德州hhpoker脚本,wepoker破解工具,教程书教程(有挂解密)-哔哩哔哩;wepo...
揭秘一下!欢乐情怀脚本辅助器i... 揭秘一下!欢乐情怀脚本辅助器ios,wepoker透视破解版,法子教程(有挂秘籍)-哔哩哔哩小薇(辅...
详情透视!aapoker安装包... 详情透视!aapoker安装包怎么使用,微信小程序微乐辅助器app,经验教程(有挂方针)-哔哩哔哩1...
专业透视!pokemmo手机版... 专业透视!pokemmo手机版修改器!原来有辅助神器(有挂攻略)-哔哩哔哩1.pokemmo手机版修...
专业透视!黑侠破解wepoke... 专业透视!黑侠破解wepoker,xpoker透视辅助,模块教程(有挂方法)-哔哩哔哩1、黑侠破解w...
总算了解!!微信小程序辅助器防... 总算了解!!微信小程序辅助器防检测,aa poker辅助,机巧教程(有挂工具)-哔哩哔哩1、下载好微...
揭幕透视!aapoker怎么设... 揭幕透视!aapoker怎么设置抽水,微乐游戏辅助脚本安装,法门教程(有挂技术)-哔哩哔哩1、进入到...
分享透视!德州私人局脚本!切实... 分享透视!德州私人局脚本!切实是真的有辅助技巧(新版有挂)-哔哩哔哩所有人都在同一条线上,像星星一样...