Mysql - filling rows for missing months -


gosh, must simple i'm struggling 'filling out missing data' issue.

i have table has following columns inserted data.

table  year  month  payment 2014    3      100 2014    5      800 2014    9      200 

and want table have full range of months payment value 2014.

month    payment   1        0   2        0   3       100   4        0   5       800    ...    12       0 

i tried using ifnull in select failed bad... , search results stackoverflow join 2 or more tables manipulate information. fastest , best solution solve problem?

for missing months can have union query months , join table

select  t1.`year`, t.`month`, coalesce(t1.payment,0) payment (select 1 `month` union  select 2 `month` union  .... select 12 `month` ) t left join your_table t1 on(t.`month` = t1.`month`) .... 

fiddle demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -