title: MySQL group by date, force to return null value if does not exists
body: <p>I built a query, to let me return average ranking of some Apps. </p>
  
  <p>But for some of them, for some month, we don't have data, cause the app is a new one (let's say, the app is out since this month, and so we are collecting data since this month)</p>
  
  <pre><code>SELECT 
      DATE_FORMAT(date, '%Y-%m'),
      app_id,
      AVG(rank)
  FROM wadstats.applestore_ranking
  where app_id IN (100,
          2,
          3,
          4,
          5,
          6)
  GROUP BY MONTH(date), app_id
  ORDER BY CASE WHEN app_id = 100 THEN 1 ELSE 2 END, date ASC
  </code></pre>
  
  <p>I was in need to show first the app_id = 100</p>
  
  <p>But for app_id = 8, I don't have data for august for exemple.</p>
  
  <p>Then results looks like</p>
  
  <pre><code>'2015-07', '100', '3.9355'
  '2015-04', '100', '49.5000'
  '2015-08', '100', '5.2258'
  '2015-05', '100', '16.3333'
  '2015-09', '100', '6.1333'
  '2015-06', '100', '7.5667'
  '2015-10', '100', '5.7727'
  '2015-04', '2', '6.0000'
  '2015-08', '2', '9.8710'
  '2015-05', '2', '6.4667'
  '2015-09', '2', '8.9667'
  '2015-06', '2', '8.5333'
  '2015-10', '2', '9.9545'
  '2015-07', '2', '10.5806'
  '2015-05', '3', '56.3929'
  '2015-09', '3', '55.1667'
  '2015-06', '3', '35.2500'
  '2015-07', '3', '38.7143'
  '2015-04', '3', '38.7500'
  '2015-08', '3', '52.5500'
  '2015-09', '4', '30.2105'
  '2015-06', '4', '27.9231'
  '2015-10', '4', '30.0000'
  '2015-07', '4', '47.0000'
  '2015-08', '4', '32.6818'
  '2015-06', '5', '46.8667'
  '2015-10', '5', '86.6667'
  '2015-07', '5', '63.5185'
  '2015-04', '5', '24.2500'
  '2015-08', '5', '67.3571'
  '2015-10', '6', '30.1818'
  </code></pre>
  
  <p>i wish instead to have null for each month even if no data was available for this specific month</p>
  
  <p><strong>Expected results</strong> </p>
  
  <pre><code>'2015-07', '100', '3.9355'
  '2015-04', '100', '49.5000'
  '2015-08', '100', '5.2258'
  '2015-05', '100', '16.3333'
  '2015-09', '100', '6.1333'
  '2015-06', '100', '7.5667'
  '2015-10', '100', '5.7727'
  '2015-04', '2', '6.0000'
  '2015-08', '2', '9.8710'
  '2015-05', '2', '6.4667'
  '2015-09', '2', '8.9667'
  '2015-06', '2', '8.5333'
  '2015-10', '2', '9.9545'
  '2015-07', '2', '10.5806'
  '2015-05', '3', '56.3929'
  '2015-09', '3', '55.1667'
  '2015-06', '3', '35.2500'
  '2015-07', '3', '38.7143'
  '2015-04', '3', '38.7500'
  '2015-08', '3', '52.5500'
  '2015-09', '4', '30.2105'
  '2015-06', '4', '27.9231'
  '2015-05', '4', NULL
  '2015-10', '4', '30.0000'
  '2015-07', '4', '47.0000'
  '2015-08', '4', '32.6818'
  '2015-06', '5', '46.8667'
  '2015-10', '5', '86.6667'
  '2015-07', '5', '63.5185'
  '2015-04', '5', '24.2500'
  '2015-08', '5', '67.3571'
  '2015-04', '6', NULL
  '2015-05', '6', NULL
  '2015-06', '6', NULL
  '2015-07', '6', NULL
  '2015-08', '6', NULL
  '2015-09', '6', NULL
  '2015-10', '6', '30.1818'
  </code></pre>
  
  <p>If i need to have 0 instead of NULL, that would be ok too, but I need to have for each month in the DB, to have value for each app_id</p>
  
  <p>Thanks so much by advance</p>