有表如下
tabel aid column value
1 name 张
1 age 20
1 sex 男
1 money 2000
2 name
2 age
2 sex
2 money
现在想把1的value复制到2的value中,column字段对应,怎么写sql?
tabel aid column value
1 name 张
1 age 20
1 sex 男
1 money 2000
2 name
2 age
2 sex
2 money
现在想把1的value复制到2的value中,column字段对应,怎么写sql?
update a t1
set value=
(select value
from a
where column=t1.column
and id=1)
where id=2
----try
update tb a
set a.value=(select b.value from tb b where a.column=b.column and b.id=1)
where exists (select 1 from tb b where a.column=b.column and b.id=1) and a.id=2
SET A1.VALUE = (SELECT A2.VALUE
FROM A A2
WHERE A1.COLUM = A2.COLUM
AND A2.ID = 1)
WHERE A1.ID = 2;