更新操作
2021-03-16 14:19:17 来源:admin 点击:662
CREATE TABLE `test2` (
`id` int(11) NOT NULL,
`filed1` varchar(255) DEFAULT NULL,
`filed2` varchar(255) DEFAULT NULL,
`filed3` int(11) DEFAULT NULL,
`filed4` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `test1` (
`id` int(11) NOT NULL,
`filed1` varchar(255) DEFAULT NULL,
`filed2` varchar(255) DEFAULT NULL,
`filed3` int(11) DEFAULT NULL,
`filed4` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
#1 更新字段1到字段2
#UPDATE test1 set filed1 = filed2
#2 更新字段4 + 8 到 字段3
#UPDATE test1 SET filed3 = filed4 + 8
#更新 字段1 和字段2 拼接 到字段 4
#UPDATE test1 SET filed4 = concat(filed1,filed2)
#插入A表的字段到b表
#INSERT INTO test2 (id,filed1,filed2,filed3,filed4) SELECT id,filed1,filed2,filed3,filed4 from test1
#更新A表的字段到B表
#update test2 a set a.filed1 = (select filed1 from test1 b where b.id=a.id)
#UPDATE test1,test2 SET test2.filed1 = test1.filed1 where test1.id = test2.id
#UPDATE test1,(SELECT * from test2) as a SET test1.filed1 = a.filed1 where test1.id = a.id
update 更新表 set 字段 = (select 参考数据 from 参考表 where 参考表.id = 更新表.id);
update table_2 m set m.column = (select column from table_1 mp where mp.id= m.id);
方法二:
update table_1 t1,table_2 t2 set t1.column = t2.column where t1.id = t2.pid;
pgsql跨表更新
UPDATE user_river_relationship SET uid=a.id FROM(
SELECT * FROM user_infor
) a WHERE a.gpsid=user_river_relationship.gpsid