有没有方便一点的复制方法?

zhuyf333 2009-06-08 04:12:04
有表如下
tabel a

id 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?
...全文
29 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pobaby 2009-06-08
  • 打赏
  • 举报
回复
UPDATE A A1
SET A1.VALUE = (SELECT A2.VALUE
FROM A A2
WHERE A1.COLUM = A2.COLUM
AND A2.ID = 1)
WHERE A1.ID = 2;
ks_reny 2009-06-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ks_reny 的回复:]
SQL code
----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
[/Quote]
我在Oracle 8.1.7中驗證通過.
bzcnc 2009-06-08
  • 打赏
  • 举报
回复
这个比较少见,对自己表中的数据进行更新,上面的都给出了更新语句,挺好的
冰心的小屋 2009-06-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bw555 的回复:]
try
SQL codeupdatea t1setvalue=(selectvaluefromawherecolumn=t1.columnandid=1)whereid=2
[/Quote]
应该行
ks_reny 2009-06-08
  • 打赏
  • 举报
回复

----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
bw555 2009-06-08
  • 打赏
  • 举报
回复
try
update a t1 
set value=
(select value
from a
where column=t1.column
and id=1)
where id=2

17,088

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧