开发者

mysql display each day in a month

开发者 https://www.devze.com 2022-12-24 20:50 出处:网络
during a month, display the infor each date, order by date, but this infor is empty in some day. how 开发者_StackOverflowcan i still display each day as a row?

during a month, display the infor each date, order by date, but this infor is empty in some day. how 开发者_StackOverflowcan i still display each day as a row?

Product  date
-----------------
20     2008-01-01
10     2008-01-02
20     2008-01-03
10     2008-01-05
09     2008-01-08
30     2008-01-09

result:

Product  date
-----------------
20     2008-01-01
10     2008-01-02
20     2008-01-03
0      2008-01-04
10     2008-01-05
0      2008-01-06
0      2008-01-07
09     2008-01-08
30     2008-01-09


In MySQL, unfortunately, you might have to have a table that contains the dates pre populated to achieve this.

You will have to then left join to this table to retrieve all the appropriate dates.

In SQL Server 2005+ you could have achieved this using a CTE statement, to recursively generate the dates required.

0

精彩评论

暂无评论...
验证码 换一张
取 消