1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| WITH Table1 AS (SELECT 1 col1, 'az' col2, TO_DATE('23/01/2012', 'DD/MM/YYYY') col3 FROM dual
UNION ALL SELECT 2 col1, 'dt' col2, TO_DATE('24/01/2012', 'DD/MM/YYYY') col3 FROM dual
UNION ALL SELECT 3 col1, 'po' col2, TO_DATE('25/01/2012', 'DD/MM/YYYY') col3 FROM dual
UNION ALL SELECT 4 col1, 'ml' col2, TO_DATE('28/01/2012', 'DD/MM/YYYY') col3 FROM dual),
Table2 AS (SELECT 1 col1, 'fg' col2, TO_DATE('24/01/2012', 'DD/MM/YYYY') col3 FROM dual
UNION ALL SELECT 2 col1, 'xb' col2, TO_DATE('21/01/2012', 'DD/MM/YYYY') col3 FROM dual
UNION ALL SELECT 2 col1, 'aa' col2, TO_DATE('21/04/2011', 'DD/MM/YYYY') col3 FROM dual
UNION ALL SELECT 3 col1, 'rf' col2, TO_DATE('26/01/2012', 'DD/MM/YYYY') col3 FROM dual
UNION ALL SELECT 4 col1, 'fg' col2, TO_DATE('30/01/2012', 'DD/MM/YYYY') col3 FROM dual)
SELECT col1,
MIN(col2) KEEP (DENSE_RANK FIRST ORDER BY col3 desc) AS col2,
MIN(col3) KEEP (DENSE_RANK FIRST ORDER BY col3 desc) AS col3
FROM (SELECT col1, col2, col3 FROM table1
UNION ALL
SELECT col1, col2, col3 FROM table2
)
GROUP BY col1 |
Partager