sql如何条件插入数据

sql如何条件插入数据

如何把空值按照id插入进去?
用insert吗


img

img

img

img


update table_b b, table_a a set b.updateTime = a.updateTime where b.id = a.id and b.updateTime is null ; 

这是两个表关联更新数据的SQL,我这边验证是可以正常更新进去的。
直接两个表链表更新即可,SQL中将要更新的表放在最前边,要更新table_b,就把table_b写在前边。

img

img


update table_name set updateTime = '' where id = 1;
update table_name set updateTime = '' where id = 2;
update table_name set updateTime = '' where id = 3;

可以换个思想使用update语句
update tb_name set updatetime = '时间' where 条件

update方法根据ID,update table_name set ‘字段名称’ = '要插入的值' where id = ‘指定的ID值’;

如果插入insert不行的话,可以用update更新的方式插入

关联表更新可以用update from语句:

update a set a.updateTime = b.updateTime from table1 a inner join table2 b on a.id=b.id where b.updateTime is null