日期:2014-05-18  浏览次数:20590 次

================这样的sql怎么写=================================
有个数据表 table 
里面有字段 a,b,c,d,e
在添加新记录的时候我要复制字段
b,c,d的内容
然后在字段a ,e里面写入新的内容

求教各位大神有没有什么的好的方法实现

------解决方案--------------------
oracle的写法:
insert into 表(id,year,b,c,d) select 1,'2012.com',b,c,dfrom 表 where rownum between 0 and 1;
------解决方案--------------------
oracle的写法:
insert into 表(id,year,b,c,d) select 1,'2012.com',b,c,d from 表 where rownum between 0 and 1;
------解决方案--------------------
sqlserver的写法:
insert into 表(id,year,b,c,d) select top 1 2,'2012.com',b,c,dfrom 表;

mysqlServer的写法:
insert into 表(id,year,b,c,d) select 2,'2012.com',b,c,dfrom 表 limit 0,1;

------解决方案--------------------
探讨
有个数据表 table
里面有字段 a,b,c,d,e
在添加新记录的时候我要复制字段
b,c,d的内容
然后在字段a ,e里面写入新的内容

求教各位大神有没有什么的好的方法实现

------解决方案--------------------
探讨
简单来说就是要达到这样的效果
把 表 table
id year b c d
1 2011 aa bb cc
变为
id year b c d
1 2011 aa bb cc
2 2012 aa bb dd

------解决方案--------------------
SQL code
insert into table select id = id + 1 , [year] = [year] + 1 , b , c, d from table where id = 1 

insert into table select id = id + 1 , [year] = [year] + 1 , b , c, d from table where [year] = 2011