首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

update嵌套两个select,该怎么处理

2012-12-18 
update嵌套两个selectupdate t_inf_tmp tmp set (orignal_useragent, orignal_date)(select useragent, i

update嵌套两个select
update t_inf_tmp tmp set (orignal_useragent, orignal_date)=
   (
      select useragent, insertdate from(
        select useragent, insertdate
          from v_his_all his
          where his.isdn=tmp.isdn
            and his.insertdate<tmp.insertdate
            order by his.insertdate desc
      )
      where rownum<=1    
   );

想将临时表中orignal_useragent, orignal_date更新为最近一次的值。上面的sql在oracle中执行完,都更新成v_his_all最大时间对应的值了。我想要的是相应号码的。求大神指点?
[最优解释]
上面别名写错了

update t_inf_tmp tmp set (orignal_useragent, orignal_date)=(
   select useragent, insertdate from(
      select useragent, insertdate, rank() over(partition by isdn order by insertdate desc) rk
      from v_his_all his1
      where his1.isdn=tmp.isdn and his1.insertdate<tmp.insertdate
   ) his2
   where his2.isdn=tmp.isdn and rk<=1
);

[其他解释]
帮顶,哈哈,
[其他解释]
update t_inf_tmp tmp set (orignal_useragent, orignal_date)=
   (
      select useragent, insertdate from(
        select useragent, insertdate, rank() over(partition by isdn order by insertdate desc) rk
          from v_his_all
          where his.isdn=tmp.isdn and his.insertdate<tmp.insertdate
      ) his
      where his.isdn=tmp.isdn and rk<=1 
   );


[其他解释]
引用:
上面别名写错了


SQL code??



12345678

update t_inf_tmp tmp set (orignal_useragent, orignal_date)=(    select useragent, insertdate from(       select useragent, insertdate, rank() over(partition ……

t_inf_tmp后面跟上别名tmp,在本地可以执行,为什么在服务器上执行,就报tmp.isdn标识符无效呢?
[其他解释]
可能是ORACLE版本不同,低版本的ORACLE不支持太多层的嵌套表使用别名,会找不到,需要稍作修改减少嵌套语句的层数

热点排行