Mysql查询一张表的数据新增到另一张表里

it2023-05-05  72

1.把B表的数据查询出新增到A表去

INSERT INTO a(id,name) SELECT b.id as id,b.name as name FROM b;

2.B表的字段满足不了A的情况下 ‘name’是对应type ,now()是对应的create_date

INSERT INTO dim_attach (type,bill_id,url,create_date) select 'name', a.id AS bill_id, a.head_address AS url,now() FROM dim_people a

mybatis写法 mapper.xml

<insert id="addDownLods" parameterType="com.entity.VideoDownLogs"> insert into video_down_logs(video_id, video_date, video_name, video_url, video_size, user_name, down_flag) select a.id as video_id ,a.load_time as video_date ,a.title as video_name,a.hdfs_url as video_url,a.size as video_size, #{userName} as user_name, 0 from video_origin a where 1=1 <if test="id !=null"> and a.id=#{id} </if> </insert>

values 不用写!!!!

最新回复(0)