关于update的求教

瘦小王 2018-03-17 07:06:42
如何通过一条update语句可以把图1的初始数据刷成图2这样的。也就是说把parent的value刷成child的value
...全文
310 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复

merge into t1
using (select id,parentid value from t1 where id<>parentid ) b
on( t1.id=b.parentid )
when matched then update set t1.value=b.value
瘦小王 2018-03-18
  • 打赏
  • 举报
回复
那就直接用update吧 update t1 seet value=(select value from (select id,parentid value from t1 where id<>parentid ) b where t1.t1.id=b.parentid) where exists (select 1 from (select id,parentid value from t1 where id<>parentid ) b where t1.t1.id=b.parentid)[/quote] 嗯,可以的,谢谢
  • 打赏
  • 举报
回复
引用 2 楼 king_bt 的回复:
好像mysql不支持merge into 的用法
那就直接用update吧 update t1 seet value=(select value from (select id,parentid value from t1 where id<>parentid ) b where t1.t1.id=b.parentid) where exists (select 1 from (select id,parentid value from t1 where id<>parentid ) b where t1.t1.id=b.parentid)
瘦小王 2018-03-18
  • 打赏
  • 举报
回复
引用 1 楼 baidu_36457652 的回复:

merge into t1
using (select id,parentid value from t1 where id<>parentid ) b
on( t1.id=b.parentid )
when matched then update set t1.value=b.value
好像mysql不支持merge into 的用法

17,086

社区成员

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

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