select nvl(xxx),sum(a) from xx gourp by ?
xxx是一个嵌套查询
(select nvl(NVL(to_char(approval_amount),(select to_char(num_field33)||'(前期费用)' from pims.o_list_project where id=s.pro_id and if_pstype='1')),0) from pims.o_list_project_sub_review where mainid=s.pro_id)
怎么group by
select id,(select nvl(NVL(to_char(approval_amount),(select to_char(num_field33)||'(前期费用)' from pims.o_list_project where id=s.pro_id and if_pstype='1')),0) from pims.o_list_project_sub_review where mainid=s.pro_id)pftze,sum(SJ_M_TZEXJ) from R_PROPLAN_EXCUTE_SUB s group by id,(select nvl(NVL(to_char(approval_amount),(select to_char(num_field33)||'(前期费用)' from pims.o_list_project where id=s.pro_id and if_pstype='1')),0) from pims.o_list_project_sub_review where mainid=s.pro_id)
ORA-22818:subquery expressions not allowed here
意思是不能嵌套吗 有解决办法?

解决方案 »

  1.   

    11G不支持双层嵌套子查询关联了,你的 id=s.pro_id 这个是关联不到外面的s表的
      

  2.   

    select (select nvl(NVL(to_char(approval_amount),(select to_char(num_field33)||'(前期费用)' from pims.o_list_project where id=s.pro_id and if_pstype='1')),0) from pims.o_list_project_sub_review where mainid=s.pro_id)pftze from R_PROPLAN_EXCUTE_SUB s 
    单独执行时能过的
    主要想要解决的是嵌套查询和sum结合 怎么分组 不能用nvl那段作为分组条件 他的别名pftze也不行
      

  3.   

    select (select nvl(NVL(to_char(approval_amount),(select to_char(num_field33)||'(前期费用)' from pims.o_list_project where id=s.pro_id and if_pstype='1')),0) from pims.o_list_project_sub_review where mainid=s.pro_id)pftze from R_PROPLAN_EXCUTE_SUB s 
    单独执行时能过的
    主要想要解决的是嵌套查询和sum结合 怎么分组 不能用nvl那段作为分组条件 他的别名pftze也不行 
      

  4.   


    select id,
    coalesce(to_char(b.approval_amount),to_char(a.num_field33)||'(前期费用)',0) pftze,
    sum(SJ_M_TZEXJ) 
    from R_PROPLAN_EXCUTE_SUB s ,
    pims.o_list_project a ,
    pims.o_list_project_sub_review  b
    where b.mainid=s.pro_id
      and a.id=s.pro_id 
      and a.if_pstype='1'
    group by id,
    coalesce(to_char(b.approval_amount),to_char(a.num_field33)||'(前期费用)',0)
    ;你试试这个,给你改了一下
      

  5.   

    这段sql是很长的。所以只能改片段sql 不能该连接
      

  6.   

    你用的那个版本的oracle