{section}{column:width=50%}
SELECT
CD,SUM(AT),SUM(QT)
FROM(SELECT CD,AT,0 QT
FROM TAB7
UNION ALL
SELECT CD,0,QT FROM TAB8)
GROUP BY CD HAVINGCD<>'C';
{column}{column:width=50%}
Execution Plan
----------------------------------------------------------
Plan hash value: 1539313887
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 |SELECTSTATEMENT | | 13 | 429 | 7 (15) | 00:00:01 |
|*1 | FILTER | | | | | |
| 2 | HASHGROUPBY | | 13 | 429 | 7 (15) | 00:00:01 |
| 3 | VIEW | | 13 | 429 | 6 (0) | 00:00:01 |
| 4 | UNION-ALL | | | | | |
| 5 | TABLE ACCESS FULL| TAB7 | 9 | 180 | 3 (0) | 00:00:01 |
| 6 | TABLE ACCESS FULL| TAB8 | 4 | 80 | 3 (0) | 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identifiedbyoperation id):
---------------------------------------------------
1 - filter("CD"<>'C')
{column}{section}