Personally, I would implement the idea expressed in Takis’ link at the application level in the code you shown above, rather than having the database server do it. I would use an array of dates, for all dates of interest, with a default order count of 0. I would then take dailyOrders to complete the array of dates with the count of orders received.
Why?
- It reduces the workload of the server.
- It reduces the bandwidth needs between the server and the application.
- It increases the chances to distribute this workload to the multiple application instances.
- It allows to have a more flexible API because you could have one /summary-non-zeros and /summary-with-zeros rather than only /summary. You would use /summary-with-zeros to provide an enriched result for /summary-with-zeros.