create or replace view vatm as
select cardno,trxcode,count(*) hjbs, sum(trxamt) hjje from atmtotal group by cardno,trxcode;select a.cardno 卡号,b.hjbs 取款笔数,c.hjje 存款笔数,b.hjje 取款金额,c.hjje 存款金额,d.hjbs 转帐笔数,d.hjje 转帐金额,a.hjbs 合计笔数,a.hjje 合计金额
from 
(
  select cardno,count(*) hjbs,sum(hjje) hjje from vatm group by cardno
) a,
(
  select cardno,hjbs,hjje from vatm where trxcode='4401'
) b,
(
  select cardno,hjbs,hjje from vatm where trxcode='4402'
) c,
(
  select cardno,hjbs,hjje from vatm where trxcode='4403'
) d
where a.cardno=b.cardno(+) and a.cardno=c.cardno(+) and a.cardno=d.cardno(+);

解决方案 »

  1.   

    SQL> select a.cardno 卡号,b.hjbs 取款笔数,c.hjje 存款笔数,b.hjje 取款金额,c.hjje 存款金额,d.hjbs 转
    帐笔数,d.hjje 转帐金额,a.hjbs 合计笔数,a.hjje 合计金额
      2  from 
      3  (
      4    select cardno,count(*) hjbs,sum(hjje) hjje from vatm group by cardno
      5  ) a,
      6  (
      7    select cardno,hjbs,hjje from vatm where trxcode='4401'
      8  ) b,
      9  (
     10    select cardno,hjbs,hjje from vatm where trxcode='4402'
     11  ) c,
     12  (
     13    select cardno,hjbs,hjje from vatm where trxcode='4403'
     14  ) d
     15  where a.cardno=b.cardno(+) and a.cardno=c.cardno(+) and a.cardno=d.cardno(+);卡号       取款笔数  存款笔数  取款金额  存款金额  转帐笔数  转帐金额  合计笔数  合计金额
    --------- --------- --------- --------- --------- --------- --------- --------- ---------
    042030003         1     50000     30000     50000                             2     80000
    042030004                                                 2      5000         1      5000
    042030005               60000               60000         1     30000         2     90000SQL>
      

  2.   

    --前面错写一个字段,改一下create or replace view vatm as
    select cardno,trxcode,count(*) hjbs, sum(trxamt) hjje from atmtotal group by cardno,trxcode
    select a.cardno 卡号,b.hjbs 取款笔数,c.hjbs 存款笔数,b.hjje 取款金额,c.hjje 存款金额,d.hjbs 转帐笔数,d.hjje 转帐金额,a.hjbs 合计笔数,a.hjje 合计金额
    from 
    (
      select cardno,count(*) hjbs,sum(hjje) hjje from vatm group by cardno  --在此改sum(hjje)
    ) a,
    (
      select cardno,hjbs,hjje from vatm where trxcode='4401'
    ) b,
    (
      select cardno,hjbs,hjje from vatm where trxcode='4402'
    ) c,
    (
      select cardno,hjbs,hjje from vatm where trxcode='4403'
    ) d
    where a.cardno=b.cardno(+) and a.cardno=c.cardno(+) and a.cardno=d.cardno(+);不知楼主合计金额是如何计算的,如结果不对,楼主可在结果集a中修改