I need to write a query in MS Access to get a count of operation by 2 dates column. Structure of my table is
start_date | end_date | f1 | f2 | f3 |
---|---|---|---|---|
2022-12-01 | 2022-12-05 | f1 | f2 | f3 |
2022-11-15 | 2022-12-07 | f1 | f2 | f3 |
2022-12-06 | 2022-12-07 | f1 | f2 | f3 |
2022-11-15 | 2022-12-06 | f1 | f2 | f3 |
I need output as for all dates of a month
date | Total start_date on date | Total end_date on date |
---|---|---|
2022-11-15 | 1 | 0 |
2022-12-01 | 1 | 0 |
2022-12-05 | 0 | 1 |
2022-12-06 | 1 | 1 |
2022-12-07 | 0 | 2 |
What I have done is (which is incorrect, since it is possible on a given start_date, the count is zero and for some end_date count is zero)
SELECT start_date, count(start_date) as startcount, tbl2.endcount FROM tbl
FULL OUTER JOIN (SELECT end_date, count(end_date) as endcount FROM tbl GROUP BY end_date) as tbl2
ON start_date=tbl2.end_date
GROUP BY start_date
ORDER BY start_date
Any suggestions?
I have already checked for the existing answers, but they do not match the requirements, since in other answers they are doing a UNION of result, which is not my question.