gaps-and-islands

MySQL how to fill missing dates in range?

白昼怎懂夜的黑 提交于 2019-11-25 22:17:54
问题 I have a table with 2 columns, date and score. It has at most 30 entries, for each of the last 30 days one. date score ----------------- 1.8.2010 19 2.8.2010 21 4.8.2010 14 7.8.2010 10 10.8.2010 14 My problem is that some dates are missing - I want to see: date score ----------------- 1.8.2010 19 2.8.2010 21 3.8.2010 0 4.8.2010 14 5.8.2010 0 6.8.2010 0 7.8.2010 10 ... What I need from the single query is to get: 19,21,9,14,0,0,10,0,0,14... That means that the missing dates are filled with 0.

Get a list of dates between two dates

橙三吉。 提交于 2019-11-25 21:57:08
问题 Using standard mysql functions is there a way to write a query that will return a list of days between two dates. eg given 2009-01-01 and 2009-01-13 it would return a one column table with the values: 2009-01-01 2009-01-02 2009-01-03 2009-01-04 2009-01-05 2009-01-06 2009-01-07 2009-01-08 2009-01-09 2009-01-10 2009-01-11 2009-01-12 2009-01-13 Edit: It appears I have not been clear. I want to GENERATE this list. I have values stored in the database (by datetime) but want them to be aggregated