I have a Oracle SQL table which stores Document Informations. The table has 3 columns (ID, creationDate, status). There are only 2 status ("STATUS1", "STATUS2")
For each available date and status, I want to have the total number of documents with those characteristics (including when total count = 0).
My code is the following:
SELECT DISTINCT TO_CHAR(D.CREATED_ON, 'DD-MM-YY') AS DATE, D.STATUS, COUNT(*) AS TOTAL
FROM DOCUMENTS D
GROUP BY DISTINCT TO_CHAR(D.CREATED_ON, 'DD-MM-YY'), D.STATUS
ORDER BY 1 ASC;
Which returns:
| DATE | STATUS | TOTAL |
|-----------|--------|-------|
| 14-01-22 | STATUS1| 2 |
| 14-01-22 | STATUS2| 1 |
| 15-01-22 | STATUS2| 3 |
| 16-01-22 | STATUS1| 2 |
I want it to return:
| DATE | STATUS | TOTAL |
|----------|--------|-------|
| 14-01-22 |STATUS1 | 2 |
| 14-01-22 |STATUS2 | 1 |
| 15-01-22 |STATUS1 | 0 | <--
| 15-01-22 |STATUS2 | 3 |
| 16-01-22 |STATUS1 | 2 |
| 16-01-22 |STATUS2 | 0 | <--
Is this possible?