一个表结构是ID,name,父ID,要求用一句SQL 查出id是1007的所有的父ID

来源:百度知道 编辑:UC知道 时间:2024/06/17 10:57:56
给我句SQL,谢谢,在Oracle中
还有一个,呵呵,帮我解决了吧,我有分,谢谢!
题目为:一个表A结构P_ID,P_NAME,另一个表B结构ID,P_ID,P_NAME,NAME,写一个SQL更新表B,将表A的值更新到表B

id 为字符型
select 父ID form 表 where id = '1007'

id 为数字型
select 父ID form 表 where id = 1007

补充:
update b
set b.name = (select a.name from a where a.id = b.id)

第一个
select 父ID from 表 where id = 1007;

第二个
insert into B (p_id,p_name) (select * from A);

更新b表中的数据
update table_b b,table_a a
where b.p_id = a.p_id
and b.p_name = a.name

查询a表中id为1007的所有的p_id
select a.p_id
from table_a a
where a.id = '1007'

update b
set b.P_NAME=a.P_NAME
where b.P_ID=a.P_ID