mysql - Return a zero for a day with no results -
i have query returns total of users registered each day. problem if day had no 1 register doesn't return value, skips it. rather returned zero
this query far
select count(*) total users created_at < now() , created_at > date_sub(now(), interval 7 day) , owner_id = ? group day(created_at) order created_at desc
edit
i grouped data count each day- date range, wanted total users registered previous 7 days
a variation on theme "build on 7 day calendar inline":
select d, count(created_at) total (select date_sub(now(), interval d day) d (select 0 d union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 ) d ) d left join users on date(created_at) = date(d) owner_id = ? or owner_id null group d order d desc
i don't have table structure @ hand, need adjustment probably. in same order of idea, see use now()
reference date. that's adjustable. anyway that's spirit...
see live demo http://sqlfiddle.com/#!2/ab5cf/11
Comments
Post a Comment