Mysql: Select all data between two dates

2019-01-01 02:26发布

I have a mysql table with data connected to dates. Each row has data and a date, like this:

2009-06-25    75
2009-07-01    100
2009-07-02    120

I have a mysql query that select all data between two dates. This is the query:

SELECT data FROM tbl WHERE date BETWEEN date1 AND date2

My problem is that I also need to get the rows between date1 and date2 even if there is no data for a day.

So my query would miss the dates that are empty between 2009-06-25 and 2009-07-01.

Can I in some way add these dates with just 0 as data?

7条回答
浅入江南
2楼-- · 2019-01-01 03:05

You can use as an alternate solution:

SELECT * FROM TABLE_NAME WHERE `date` >= '1-jan-2013' 
OR `date` <= '12-jan-2013'
查看更多
登录 后发表回答