最近有一个数据导入的需求: 就是将项目1中的(一部分)数据导入到项目2 ;构思一下这个sql应该怎么写
思路: 1、把数据取出来, 2、修改主要字段,3、插入数据
一、把首先把要考呗的内容查询出来(根据项目ID查询并且主键ID筛选)
SELECT ( id, `name`,enname,method,url,query_params,input_type,input_test_data,input_body, out_type,out_body,out_test_data,inter_type_id,project_id,memo,ispage,page_size,page_index,update_time,create_time,header,result,save_key,total_key,status_code_key,success_code,show_message FROM bue_interface_entity WHERE project_id='ed47f01dbdc243f58679' AND id IN ('e8db086ff0284d81a5a8','e8db086ff0284d81a5a9')
二、替换字段:id;inter_type_id;project_id
SELECT (SELECT CEILING(RAND()*9000000000000000+1000000000000000)) id, `name`,enname,method,url,query_params,input_type,input_test_data,input_body, out_type,out_body,out_test_data,'061c5f989d5746c98418' inter_type_id,'7a9c89097d0c4c729515' project_id,memo,ispage,page_size,page_index,update_time,create_time,header,result,save_key,total_key,status_code_key,success_code,show_message FROM bue_interface_entity WHERE project_id='ed47f01dbdc243f58679' AND id IN ('e8db086ff0284d81a5a8','e8db086ff0284d81a5a9')
三、插入数据
INSERT INTO bue_interface_entity(id,`name`,enname,method,url,query_params,input_type,input_test_data,input_body, out_type,out_body,out_test_data,inter_type_id,project_id,memo,ispage,page_size,page_index,update_time,create_time,header,result,save_key,total_key,status_code_key,success_code,show_message)
四、完整sql:
INSERT INTO bue_interface_entity(id,`name`,enname,method,url,query_params,input_type,input_test_data,input_body, out_type,out_body,out_test_data,inter_type_id,project_id,memo,ispage,page_size,page_index,update_time,create_time,header,result,save_key,total_key,status_code_key,success_code,show_message) SELECT (SELECT CEILING(RAND()*9000000000000000+1000000000000000)) id, `name`,enname,method,url,query_params,input_type,input_test_data,input_body, out_type,out_body,out_test_data,'061c5f989d5746c98418' inter_type_id,'7a9c89097d0c4c729515' project_id,memo,ispage,page_size,page_index,update_time,create_time,header,result,save_key,total_key,status_code_key,success_code,show_message FROM bue_interface_entity WHERE project_id='ed47f01dbdc243f58679' AND id IN ('e8db086ff0284d81a5a8','e8db086ff0284d81a5a9')
五、总结:
这个sql可能很简单,但是对于我这种不怎么搞Java的来说。这个sql比较有代表性,在此记录一下,学会了新的知识.
网友评论