將一個表的結果集插入到另一個表中


舉例1:

insert into table_b(time,score,totalscore)
select time,score,sum(score) over (order by time)
from table_a



舉例2:

insert into JobInfo_analysis(Salary,address,jobname,company,companysize,companytype,Educational,remak,Releasetime,created,id,LinkStatus,Reply,MyNote,LoveLevel) 
select Salary,address,jobname,company,companysize,companytype,Educational,remak,Releasetime,created,id,LinkStatus,Reply,MyNote,LoveLevel 
from JobInfo 
where address like'%北京%'      
    and (jobname like'%ios%' or jobname like'%iphone%' or remak like '%ios%' or remak like 'iphone')      
    and cast(substr(Salary,7,12) as int) >= 20001  
    and cast(substr(Salary,7,12) as int) <= 35000    
    and company not like '%咨詢%' 
    and company not like '%顧問%'    
    and company not like '%獵頭%'    
    and company not like '%管理%'
    and company not like '%獵聘%'
    and company not like '%某公司%'
    and company not like '%人力資源%'
    and company not like '%人才服務%'    
    

 總結:

SQL數據庫中把一個表中的數據復制到另一個表中

1、如果是整個表復制表達如下:

insert into table1 select  * from table2


2、如果是有選擇性的復制數據表達如下:

insert into table1(column1,column2,column3...) select column1,column2,colunm3... from table2


3、一個數據庫中的表中的數據復制到另一個數據庫中的一個表,使用方法如下:

insert into 數據庫A.dbo.table1(col1,col2,col3...) select col1,col2,col3... from 數據庫B.dbo.table2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM