MySQL: Select All Dates In a Range Even If No Records Present -
I have database of users I want to create a graph based on user base development. My query is now:
SELECT DATE (datecreated), count (*) AS numbers from users where date (datecreated) & gt;
this about > Em> What do I need if one of us If 0 users come in the day, then that day is not returned as 0 value, it is only left and the next day at least one user has returned. How can I get some (PEDO-feedback):
date 1 5 date 2 date 8 date 3 date date 0 date 9 9 etc ...
< P> Where do the dates appear in the sequential order with the remaining dates with zero? Thank you!
I hope you find out the rest. Select
from (select date_add ('2003-01-01 00: 00: 00.000', INTERVAL n5.num * 10000 + n4 dated * 1000 + n3.num * 100 + n2 Num * 10 + n1.num DAY) (select 0 as num union All selected 1 union all selected 2 associations all selected 3 associations all selected 4 associations all selected 5 associations all selected 6 associations all selected 7 associations All selected 8 associations all select 9) N1, (0 Select 0 number as number union All selected 1 union all selected 2 associations all selected 3 associations all selected 4 associations all selected 5 union all Select 6 Select All Union 7 All Select 8 All Select All 9) N2, (Select 0 All Unions as 0 points Choose All Union 2 Elections 3 Union All Select 4 Union All Select 5 associations All selected 6 associations All selected 7 associations All selected 8 associations all selected 9) N3, (0 Select 0 points each Union All selected 1 union Select all 2 Union Select all 3 Union Select all 4 Union All selected 5 associations All selected 6 associations All selected 7 associations all selected 8 associations all selected 9) N4, (Select 0 Number as union 0 Select All Union 2 All Select 2 Union Select All 3 Union Select All 4 Union All 5 Union All 6 Select the Union Select all selected associations 8 Select the union 8 Select the union all 9) N5 where the date is & gt; '2011-01-02 00: 00: 00.000' and date & lt; Date now according to date
select n3.num * 100 + n2.num * 10 + n1.num as the date
You will get columns with a maximum of 0 (* 3) * 100 + maximum (N2) * 10 + maximum (N1)
because we have a maximum of 3 N 3, select 399, plus 0 -> 400 records (dates in the calendar) will return.
You can tune your dynamic calendar by limiting it, for example, now () you have now ().
Comments
Post a Comment