{section}{column:width=50%}
select yyyymm, nvl(sum(inp_amt),0), nvl(sum(out_amt),0)
from (select MANAGE_NUM, substr(INPUT_DATE,1,6) yyyymm,
AMT inp_amt, to_number(null) out_amt
from INPUT
where INPUT_DATE between '20060301' and '20060430'
union all
select MANAGE_NUM, substr(OUTPUT_DATE,1,6) yyyymm,
to_number(null) inp_amt, AMT out_amt
from OUTPUT
where OUTPUT_DATE between '20060301' and '20060430')
group by yyyymm;
YYYYMM NVL(SUM(INP_AMT),0) NVL(SUM(OUT_AMT),0)
------------ ------------------- -------------------
200604 2000 2000
200603 7000 7000
Elapsed: 00:00:00.05
{column}
{column:width=50%}
Execution Plan
----------------------------------------------------------
Plan hash value: 601556075
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 18 | 612 | 7 (15)| 00:00:01 |
| 1 | HASH GROUP BY | | 18 | 612 | 7 (15)| 00:00:01 |
| 2 | VIEW | | 18 | 612 | 6 (0)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
|* 4 | TABLE ACCESS FULL| INPUT | 9 | 171 | 3 (0)| 00:00:01 |
|* 5 | TABLE ACCESS FULL| OUTPUT | 9 | 171 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
----------------------------------------------------------------------
4 - filter("INPUT_DATE">='20060301' AND "INPUT_DATE"<='20060430')
5 - filter("OUTPUT_DATE">='20060301' AND "OUTPUT_DATE"<='20060430')
{column}{section}