I've two tables (table1 and table2) that share a column (day_code number).
I want to obtain the count of records that each table have from a minimum day_code and group by the results by day_code.
Table 1 (number of records by day_code)
20160703 - 5
20160704 - 4
Table 2 (number of records by day_code)
20160703 - 5
20160704 - 4
I need something like that:
----------------------------------------------------
DAY_CODE | TABLE 1 | TABLE 2 |
20160703 | 5 | 5 |
20160704 | 4 | 4 |
I'm using that query:
SELECT *
FROM
(
SELECT day_code, COUNT(day_code) AS TB1 FROM TABLE1 GROUP BY day_code
UNION ALL
SELECT day_code, COUNT(day_code) AS TB2 FROM TABLE2 GROUP BY day_code
) s
where day_code between 20160703 and 20160704
I'm obtaing this:
DAY_CODE | TB1
20160703 | 5
20160704 | 4
20160703 | 5
20160704 | 4
Can you help me?
Thank you in advance for your advices, LR