{column:width=50%}


select substr(yyyymm,1,6), nvl(sum(inp_amt),0), nvl(sum(out_amt),0)
from (select MANAGE_NUM, INPUT_DATE yyyymm,
             AMT inp_amt, to_number(null) out_amt
      from INPUT
      union all
      select MANAGE_NUM, OUTPUT_DATE yyyymm,
             to_number(null) inp_amt, AMT out_amt
      from OUTPUT)
where yyyymm between substr('20060301',1,6) and substr('20060430',1,6)
group by substr(yyyymm,1,6);

SUBSTR(YYYYM NVL(SUM(INP_AMT),0) NVL(SUM(OUT_AMT),0)
------------ ------------------- -------------------
200603                      7000                7000

Elapsed: 00:00:00.04

{column}{column:width=50%}


Execution Plan
--------------------------------
Plan hash value: 601556075

-------------------------------------------------------------------------------
| Id  | Operation            | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |        |    14 |   448 |     7  (15)| 00:00:01 |
|   1 |  HASH GROUP BY       |        |    14 |   448 |     7  (15)| 00:00:01 |
|   2 |   VIEW               |        |    14 |   448 |     6   (0)| 00:00:01 |
|   3 |    UNION-ALL         |        |       |       |            |          |
|*  4 |     TABLE ACCESS FULL| INPUT  |     7 |   133 |     3   (0)| 00:00:01 |
|*  5 |     TABLE ACCESS FULL| OUTPUT |     7 |   133 |     3   (0)| 00:00:01 |
-------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   4 - filter("INPUT_DATE">='200603' AND "INPUT_DATE"<='200604')
   5 - filter("OUTPUT_DATE">='200603' AND "OUTPUT_DATE"<='200604')

{column}