fragments

May 27, 2019

MySQL查询数据并插入

Last updated at: May 27, 2019

查询user表中的type不为1的数据并插入employee表:

-- 查询字段列表的字符串
select GROUP_CONCAT(COLUMN_NAME SEPARATOR ',') from `information_schema`.`COLUMNS` WHERE TABLE_NAME = 'employee';

-- 查询并插入
insert into employee(id,mobile,school_id,school_limit,nick_name,sex,picture_url,type,active,contact_mobile,password,salt,token,old_access_token_md5,forum_vest,forum_nickname,forum_head_portrait_url,status,create_time,update_time,delete_time) 
select id,mobile,school_id,school_limit,nick_name,sex,picture_url,type,active,contact_mobile,password,salt,token,old_access_token_md5,forum_vest,forum_nickname,forum_head_portrait_url,status,create_time,update_time,delete_time from user
where type != 1;

(26 words)