子查询中带orderby的Oracle SQL::Rownum抛出缺少括号
我的sql如下所示。它正在为包含orderby子句的行抛出缺少的括号。如何重写此查询以克服此错误子查询中带orderby的Oracle SQL::Rownum抛出缺少括号,sql,oracle,subquery,Sql,Oracle,Subquery,我的sql如下所示。它正在为包含orderby子句的行抛出缺少的括号。如何重写此查询以克服此错误 update MY_TABLE1 a set (my_addr)= (select my_addr from MY_TABLE1 b where b.code1=a.code1 and b.code2=a.code2 and b.my_addr is not null and rownum = 1
update MY_TABLE1 a
set (my_addr)=
(select my_addr
from MY_TABLE1 b
where b.code1=a.code1
and b.code2=a.code2
and b.my_addr is not null
and rownum = 1
order by LAST_UPDTD_TMSTMP DESC)
where a.my_addr is null
and exists (select 1
from MY_TABLE1 b
where b.code1=a.code1
and b.code2=a.code2
and b.my_addr is not null)
如果我尝试再创建一个嵌套子查询,则对别名“a”的引用将消失
update MY_TABLE1 a
set (my_addr)=
(select my_addr from (select my_addr
from MY_TABLE1 b
where b.code1=a.code1
and b.code2=a.code2
and b.my_addr is not null
order by LAST_UPDTD_TMSTMP DESC) where rownum = 1)
where a.my_addr is null
and exists (select 1
from MY_TABLE1 b
where b.code1=a.code1
and b.code2=a.code2
and b.my_addr is not null)
非常感谢任何指点 您可以使用
keep
获取所需的值:
update MY_TABLE1 a
set my_addr = (select max(my_addr) keep (dense_rank first order by LAST_UPDTD_TMSTMP DESC)
from MY_TABLE1 b
where b.code1 = a.code1 and
b.code2 = a.code2 and
b.my_addr is not null
)
where a.my_addr is null and
exists (select 1
from MY_TABLE1 b
where b.code1 = a.code1 and
b.code2 = a.code2 and
b.my_addr is not null
);
如果您能提供示例数据,那将很有帮助。谢谢您的解决方案。这成功了!!非常感谢。