MySQL count row with group by dayofweek including zero result -


i've made query retrieve daily data week. hope of getting table follows:

  hari   total  finish   issue    ------  ------  ------  --------  1       0       0         0  2       0       0         0  3       1       0         1  4       1       1         0  5       0       0         0  6       0       0         0  7       0       0         0 

this query:

select  dayofweek(`waktu`) hari, coalesce( (count(*) ), 0) total,  count(if(`jarak`<70,1,null)) finish,  count(if(`jarak`>70,1,null)) issue  `presensi`  weekofyear(`waktu`)=weekofyear(now()) group hari; 

but, query not show 0 result. how show day of week including day emty data?

i have solve problem. create dummy table list of day(idea @drew-pierce). query:

select    h.`id`,    coalesce(d.total,0) total,    coalesce(d.finish,0) finish,     coalesce(d.issue,0) issue   hari_dummy h  left join  (   select      dayofweek(p.waktu) hari,     count(p.waktu) total,     count(if(p.`jarak` < 70, 1, null)) finish,     count(if(p.`jarak` > 70, 1, null)) issue        `presensi` p          weekofyear(waktu) = weekofyear(now())    group hari  ) d  on d.hari = h.`id`  order h.id asc; 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -