简体   繁体   English

mysql显示一个月中的每一天

[英]mysql display each day in a month

during a month, display the infor each date, order by date, but this infor is empty in some day. 在一个月中,显示每个日期的信息,按日期排序,但是该信息在某天是空的。 how can 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. 不幸的是,在MySQL中,您可能必须有一个包含预填充日期的表才能实现此目的。

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. 在SQL Server 2005+中,您可以使用CTE语句来实现此目的,以递归方式生成所需的日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM