本帖最后由 qq56961628 于 2012-03-31 19:34:49 编辑

解决方案 »

  1.   

    黄色部分的 cusromer1.f_key就会失效是什么意思
      

  2.   

    黄色部分的 cusromer1.f_key就会失效是什么意思
      

  3.   


    select customer1.f_key form gr_p_customer customer1
    where customer1.f_status = '2' and customer1.f_usesign = '0' and customer1.f_branch = '123123123123123' and
    (select f_taskgoing from
    (select task3.f_taskgoing from gr_c_task task3 where task3.f_customer = customer1.f_key order by task3.f_insettime desc)
    where rownum<=1
    )  
    in ('3',)失效?不大明白LZ的意思是第一句里面customer1.f_key查不到数据还是?and和in中间的查询返回的值是对的吧 ?  
      

  4.   


    对不起啊,不知道为什么不能编辑自己的帖子。黄色部分是我开始写的 我以为颜色会出来 但是没出来就是第二个子查询的  customer1.f_key 标识符失效
      

  5.   


      嗯  这个肯定会失效呢  嵌套2层了 customer1这个在里面不能被识别出来
      

  6.   

    再添加一个可以吧?select customer1.f_key form gr_p_customer customer1
    where customer1.f_status = '2' and customer1.f_usesign = '0' and customer1.f_branch = '123123123123123' and
    (select f_taskgoing from
            (select task3.f_taskgoing,t1.f_key 
             from gr_c_task task3 ,gr_p_customer t1
             where task3.f_customer = f_key 
             order by task3.f_insettime desc) t2
    where rownum<=1 and customer1.f_key=t2.f_key
    )  
    in ('3',)
      

  7.   


    会提示红色部分ORA-00923: 未找到要求的 FROM 关键字
      

  8.   


    我的问题 from 写错了。SQL能运行成功 我看看能不能符合业务要求 谢谢。
      

  9.   


      还真没注意  LZ 你的sql中from都写错了 你写成form 了
      

  10.   


    嘿嘿。SQL是这样的 这样就能运行成功了。 但是有个问题。
    现在库里 customer表里有600万数据,Task表里有700万数据
    所以不得不考虑效率问题
    您看看还有什么能优化的地方么。。感激不尽。。
      

  11.   


    这条SQL是框架 buffer.Append()拼出来的,我跟踪出来的。
    应该不能联合查询。
    http://stackoverflow.com/questions/2048244/oracle-subquery-does-not-see-the-variable-from-the-outer-block-2-levels-up这里面的解决方法好像跟您的一样。 至于优化问题 我再想想。感谢感谢感谢。