各位大侠,帮忙看看这段SQL有错吗?~~~ 我弄不明白了!~~ 有不明白的地方可以问我谢谢了!
select 'N',
       oma01,
       ' ',
       ' ',
       '',
       isa01,
       oma23,
       isa08t - nvl(sum(tc_oob09), 0),
       isa08t * oma24 - nvl(sum(tc_oob10), 0),
       oma00,
       oma55,
       oma54t
  from (SELECT 'N',
               oma01,
               ' ',
               ' ',
               '',
               isa01,
               oma23,
               isa08t,
               isa08t * oma24,
               oma00,
               oma55,
               oma54t
          FROM omab_tmp, isa_file
         where isa04 = oma01) a,
       (select tc_oob16, nvl(sum(tc_oob09), 0), nvl(sum(tc_oob10), 0)
          from tc_ooa_file, tc_oob_file
         where tc_ooa01 = tc_oob01
           and tc_ooaconf <> 'X'
         group by tc_oob16) b
 where a.isa01 = b.tc_oob16(+) 

解决方案 »

  1.   

    isa08t - nvl(sum(tc_oob09), 0),
      isa08t * oma24 - nvl(sum(tc_oob10), 0),
    里面的nvl(sum(tc_oob09), 0),
    和这个 nvl(sum(tc_oob10), 0)需要建立别名使用,不能直接用
      

  2.   

    有些问题 select 'N',
      a.oma01,
      ' ',
      ' ',
      '',
      a.isa01,
      a.oma23,
      a.isa08t - b.tc_oob09,
      a.isa08toma24 - b.tc_oob10,
      a.oma00,
      a.oma55,
      a.oma54t
      from (SELECT 
      c.oma01 as oma01,
      c.isa01 as isa01,
      c.oma23 as oma23,
      c.isa08t as isa08t,
      c.isa08t * oma24 as isa08toma24,
      c.oma00 as oma00,
      c.oma55 as oma55,
      c.oma54t as oma54t
      FROM omab_tmp c , isa_file d
      where c.isa04 = d.oma01) a, --  omab_tmp 和 isa_file 表结构 不清楚,不晓得这些字段是什么表的。
      (select tc_oob16 as tc_oob16, nvl(sum(tc_oob09), 0) as tc_oob09, nvl(sum(tc_oob10), 0) as tc_oob10
      from tc_ooa_file, tc_oob_file
      where tc_ooa01 = tc_oob01
      and tc_ooaconf <> 'X'
      group by tc_oob16) b
     where a.isa01 = b.tc_oob16(+) 
      

  3.   

    额,上面的SQL,不能直接使用。 还有好多点要改的。字段最好要使用别名。并且,俩个表关联查询的时候, 字段是属于哪个表的,也要说清楚哇
      

  4.   

    真想知道那个牛人写的sql  
      

  5.   

    1、'N'等常量在内层子查询不需要列,在最后一层写就可以了
    2、isa08t - nvl(sum(tc_oob09), 0)等没试过,不知道这样写会不会有问题
    如果可以,至少不建议这样写。可以改为:在内层先GROUP BY,并对需要SUM的执行计算,赋给别名试试如下:
    select 'N',
        oma01,
        ' ',
        ' ',
        '',
        isa01,
        oma23,
        isa08t - nvl(tc_oob09_sum, 0),
        isa08t * oma24 - nvl(tc_oob10_sum, 0),
        oma00,
        oma55,
        oma54t
      from (SELECT oma01,isa01,oma23,isa08t,oma24,oma00,oma55,oma54t
              FROM omab_tmp, isa_file
              where isa04 = oma01) a,
           (select tc_oob16, nvl(sum(tc_oob09), 0) tc_oob09_sum, nvl(sum(tc_oob10), 0) tc_oob10_sum
              from tc_ooa_file, tc_oob_file
              where tc_ooa01 = tc_oob01 and tc_ooaconf <> 'X'
              group by tc_oob16) b
       where a.isa01 = b.tc_oob16(+);
      

  6.   

    主要是把内层的sum 直接拿到外层来了,内层的nvl(sum(tc_oob09), 0), nvl(sum(tc_oob10), 0)
    这两个列要取一个别名,在外层引用时,分别用别名应该就可以