复制记录的sql语句

sql中复制一条记录的语法为:

 insert into 表名 select from 表名 where 条件;



复制一条记录

INSERT  into  account(id,name,money,PASSWORD)  select 4,name,money,PASSWORD from account where id=3

复制多条记录

INSERT INTO ldp_analy_model_select (id,model_id,select_name,as_name,field_name,field_type,create_by,create_time) SELECT
 replace(uuid(),'-',''),model_id,select_name,as_name,field_name,field_type,create_by,create_time
FROM ldp_analy_model_select WHERE  field_type = 0

xml中的写法

<insert id="copyRecords"  >
     INSERT INTO ldp_analy_model_select (
		id,
		model_id,
		select_name,
		as_name,
		field_name,
		field_type,
		create_by,
		create_time
	) SELECT
    replace(uuid(),'-',''),
		#{newModelId},
		select_name,
		as_name,
		field_name,
		field_type,
		create_by,
		create_time
	FROM
		ldp_analy_model_select
	WHERE
		model_id = #{oldModelId}
  
  </insert>
实现对一条语句的复制


insert into 表(月份,字段2,字段3,字段4...)
select '201007',字段2,字段3,字段4...
from 表 
where 表.月份='201006'
思想就是先把满足条件的数据(其中月份字段不取)取出来然后和你要的日期一起插入原来的表中

猜你喜欢

转载自blog.csdn.net/onlyxufeifei/article/details/79221452