不好意思~~,给的表太乱了,重给一次~~
=================|========================|
      TR01       |          TR02          |
CUSIDT  CUSNAM   | CUSIDT  CLCNUM  PRDCDE |
客户号 客户名称  | 客户号 合同编号 产品码 |
=================|========================|
 001    江滨酒店 |  002     0003    la    |
 002    实达汽车 |  003     0006    lb    |
 003    江南制药 |  004     0012    ld    |
 004    华东电力 |  005     0025    la    |
 005    丽晶酒店 |  006     0009    lb    |
 006    东方实业 |  001     0023    ld    |
 007    长江集团 |  007     0001    le    |
 008    广华电器 |  008     0004    lc    |
 f09    急 宅 送 |  010     0022    lo    |
 010    华城电子 |  f09     0008    ld    |
                 |  007     0002    la    |
                 |  010     0005    lb    |
                 |  003     0030    lc    |
                 |  004     0031    ld    |
|=============================================== 
|                   TR03                         
|CUSIDT  CLCNUM  USDCRT CURCDE  OSDAMTC  AUDCLA  
|客户号 合同编号 折算率 贷款币种 贷款额 审核结果 
|=============================================== 
|  010     0005     0      001     10000    0    
|  002     0003     9      014      2350    1    
|  003     0006     9      014      3000    0    
|  004     0012     0      001     24000    1    
|  005     0025     9      014      3520    0    
|  006     0009     0      001     35620    0    
|  001     0023     0      001     18000    1    
|  007     0001     9      014      2000    0    
|  008     0004     0      001     14600    1    
|  010     0022     0      001     10000    0    
|  f09     0008     0      001     15400    1    
|  007     0002     9      014      2400    0    
|  003     0030     0      001       120    2    
|  004     0031     0      001       240    0    
                                                 

解决方案 »

  1.   

    14:01:06 SQL> create table tr01(
      2    CUSIDT varchar2(20),
      3    CUSNAM varchar2(20)
      4* )
    14:01:18 SQL> ;
    14:01:20 SQL> 表已创建。已用时间:  00: 00: 02.0014:03:01 SQL> create table tr02(
      2  CUSIDT varchar2(20),
      3  CLCNUM varchar2(20),
      4* PRDCDE varchar2(20))
    14:03:13 SQL> ;表已创建。14:03:18 SQL> create table tr03(
    14:03:35   2  CUSIDT varchar2(20),
    14:03:44   3  CLCNUM varchar2(20),
    14:03:52   4  USDCRT number(5,2),
    14:04:08   5  CURCDE varchar2(20),
    14:04:19   6  OSDAMTC number(10,2)
    14:04:29   7  AUDCLA varchar2(50))表已创建。已用时间:  00: 00: 02.0516:05:24 SQL> insert into tr03(CUSIDt,CLCNUM,usdcrt,curcde, OSDAMTC,AUDCLA)values('002','0003',9,'014',2350,'1');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr03(CUSIDt,CLCNUM,usdcrt,curcde, OSDAMTC,AUDCLA)values('003','0006',9,'014',3000,'0');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr03(CUSIDt,CLCNUM,usdcrt,curcde, OSDAMTC,AUDCLA)values('f09','0008',0,'001',15400,'1');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr02(CUSIDT,CLCNUM,PRDCDE)values('002','0003','la');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr02(CUSIDT,CLCNUM,PRDCDE)values('003','0006','lb');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr02(CUSIDT,CLCNUM,PRDCDE)values('f09','0008','ld');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr01(CUSIDT,CUSNAM)values('002','实达汽车');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr01(CUSIDT,CUSNAM)values('003','江南制药');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:26 SQL> insert into tr01(CUSIDT,CUSNAM)values('f09','急 宅 送');已创建 1 行。已用时间:  00: 00: 00.00
    16:05:33 SQL> commit;提交完成。已用时间:  00: 00: 00.00
    16:05:35 SQL> select ttt.cusidt,ttt.usa,ttt.china,tt.usdcrt*ttt.usa/100+ttt.china,ttt.A,ttt.B from    
    16:06:27   2  ( select c.cusidt as cusidt,sum(decode(curcde,'014',OSDAMTC,0)) as usa,
    16:06:27   3           sum(decode(curcde,'001',OSDAMTC,0)) as china,
    16:06:27   4           sum(decode(AUDCLA,'0',0,1)) as A,
    16:06:27   5           sum(decode(AUDCLA,'2',0,1)) as B
    16:06:27   6      from tr03 c,tr02 t
    16:06:27   7     where ltrim(c.cusidt, '0123456789') is null 
    16:06:27   8       and c.cusidt=t.cusidt
    16:06:27   9     group by c.cusidt
    16:06:27  10  ) ttt,(select usdcrt,tr03.cusidt as cusidt from tr03,tr02 where tr03.cusidt=tr02.cusidt 
    16:06:28  11                        and ltrim(tr03.cusidt, '0123456789') is null )tt
    16:06:28  12                        where ttt.cusidt=tt.cusidt;CUSIDT                      USA      CHINA TT.USDCRT*TTT.USA/100+TTT.CHINA          A          B
    -------------------- ---------- ---------- ------------------------------- ---------- ----------
    002                        2350          0                           211.5          1          1
    003                        3000          0                             270          0          1已用时间:  00: 00: 00.00
    16:06:30 SQL>
      

  2.   

    SQL> select ttt.cusidt,ttt.usa,ttt.china,tt.usdcrt*ttt.usa/100+ttt.china,ttt.A,ttt.B from
      2  ( select c.cusidt as cusidt,sum(decode(curcde,'014',OSDAMTC,0)) as usa,
      3           sum(decode(curcde,'001',OSDAMTC,0)) as china,
      4           sum(decode(AUDCLA,'0',0,1)) as A,
      5           sum(decode(AUDCLA,'2',0,1)) as B
      6      from tr03 c,tr02 t
      7     where ltrim(c.cusidt, '0123456789') is null
      8       and c.cusidt=t.cusidt
      9     group by c.cusidt
     10  ) ttt,(select usdcrt,tr03.cusidt as cusidt from tr03,tr02 where tr03.cusidt=tr02.cusidt
     11                        and ltrim(tr03.cusidt, '0123456789') is null )tt
     12                        where ttt.cusidt=tt.cusidt
     13  ;CUSIDT                      USA      CHINA TT.USDCRT*TTT.USA/100+TTT.CHIN          A          B
    -------------------- ---------- ---------- ------------------------------ ---------- ----------
    002                        2350          0                          211.5          1          1
    003                        3000          0                            270          0          1
      

  3.   

    西西,这个需求可以用loop循环来实现吗?好像用loop循环的话会比较简单,但是我又编不出,望赐教啊~~!!
      

  4.   

    西西~~,这个需求能用loop循环来实现吗?好象用loop循环会变简单好多的~~,但是我又编不出,望赐教啊~~!!
      

  5.   

    create or replace procedure test_1 is
    cursor cur is 
       select a.cusidt,a.cusnam ,b.clcnum,b.prdcde,c.usdcrt,c.curcde,c.osdamtc,c.audcla from tr01 a ,tr02 b,tr03 c where a.cusidt=b.cusidt and b.clcnum=c.clcnum;
      v_cusidt varchar2(10);
      v_cusnam varchar2(10);
      v_clcnum varchar2(10);
      v_prdcde varchar2(10);
      v_usdcrt varchar2(10);
      v_curcde varchar2(10);
      v_osdamtc varchar2(10);
      v_audcla varchar2(10);
      
      us_num number;
      rmb_num number;
    begin
       open cur;
       loop 
         <<lp_1>>
          fetch cur into v_cusidt,v_cusnam,v_clcnum,v_prdcde,v_usdcrt,v_curcde, v_osdamtc,v_audcla;
          
          if substr(v_cusidt,1,1)>'0' or  substr(v_cusidt,1,1)>'9' then 
              null;
              goto lp_1;
          end if;
          --美无
          if (v_prdcde ='1a' or v_prdcde ='1b') and v_CURCDE='014' then 
              us_num:=us_num+OSDAMTC;
          end if;
          
          
          --其他的你就根据自己的需要去增加吧,今天到这里吧,有什么明天交流!
          --最后插入到临时表中
       end loop;  
    end test_1;
      

  6.   

    取得前三
    select * from (select rownum num,aa.* from (select  ttt.cusidt,ttt.usa,ttt.china,tt.usdcrt*ttt.usa/100+ttt.china as hl,ttt.A,ttt.B from
      ( select c.cusidt as cusidt,sum(decode(curcde,'014',OSDAMTC,0)) as usa,
               sum(decode(curcde,'001',OSDAMTC,0)) as china,
               sum(decode(AUDCLA,'0',0,1)) as A,
               sum(decode(AUDCLA,'2',0,1)) as B
          from tr03 c,tr02 t
         where ltrim(c.cusidt, '0123456789') is null
           and c.cusidt=t.cusidt
         group by c.cusidt
      ) ttt,(select usdcrt,tr03.cusidt as cusidt from tr03,tr02 where tr03.cusidt=tr02.cusidt
                            and ltrim(tr03.cusidt, '0123456789') is null )tt
                            where ttt.cusidt=tt.cusidt
                            order by hl desc)aa) where num<=3