现在有一张表,字段如下:
id name parent_name parent_id
001 jack tom
002 tom
数据库现在id、name、parent_name都已经有数据了,但是parent_id还没有,
请问如何用一个update语句,查到parent_id并补上?(就是update上面第一行的parent_id为002).希望各位高手指教!数据库update
id name parent_name parent_id
001 jack tom
002 tom
数据库现在id、name、parent_name都已经有数据了,但是parent_id还没有,
请问如何用一个update语句,查到parent_id并补上?(就是update上面第一行的parent_id为002).希望各位高手指教!数据库update
解决方案 »
- sql语句 计算在线时间?
- oracle约束问题!
- ORA-04031:无法分配4096字节的共享内存("shared pool
- ORacel行列转换问题
- oracle一次创建多个表
- 存储过程中 update 后如何取到更新结果!急急急
- 安装oracle 时自动创建的数据库与配置oms 时创建的数据库有何区别。
- Enterprise Manager中没有Configuration Assistant,怎么建资料档案库?
- procedure 和 cursor 的基础问题
- oracle dataguard中如何设置STANDBY_FILE_MANAGEMENT为MANUAL?
- oracle 更新语句死锁问题?????
- 查询不到数据时设一个默认值
update table set parent_id=id where parent_id is null;
这个意思吗?
update table set parent_id=id where parent_name in(
select parent_name from table where parent_name ||parent_id is not null
)
这个意思吗?
update table set parent_id=id where parent_name in(
select parent_name from table where parent_name ||parent_id is not null
)
不是,就比如jack的父亲是tom,然后现在需要找到tom的id(就是002),填到jack的parent_id上
update t1
set parent_id= (select id from t1 t where t.name = t1.parent_name)
where parent_id is null and parent_name is not null