SQL group by date, but get dates w/o records too
问题 Is there an easy way to do a GROUP BY DATE(timestamp) that includes all days in a period of time, regardless of whether there are any records associated with that date? Basically, I need to generate a report like this: 24 Dec - 0 orders 23 Dec - 10 orders 22 Dec - 8 orders 21 Dec - 2 orders 20 Dec - 0 orders 回答1: Instead of using GROUP BY, make a table (perhaps a temporary table) which contains the specific dates you want, for example: 24 Dec 23 Dec 22 Dec 21 Dec 20 Dec Then, join that table