title: MySQL CASE WHEN THEN empty case values
body: <pre><code>    SELECT CASE WHEN age IS NULL THEN 'Unspecified' 
                  WHEN age &lt; 18 THEN '&lt;18' 
                  WHEN age &gt;= 18 AND age &lt;= 24 THEN '18-24' 
                  WHEN age &gt;= 25 AND age &lt;= 30 THEN '25-30' 
                  WHEN age &gt;= 31 AND age &lt;= 40 THEN '31-40' 
                  WHEN age &gt; 40 THEN '&gt;40' 
              END AS ageband, 
              COUNT(*) 
         FROM (SELECT age 
                 FROM table) t 
     GROUP BY ageband
  </code></pre>
  
  <p>This is my query. These are the results:
  <img src="https://i.stack.imgur.com/eCyVC.png" alt="enter image description here"></p>
  
  <p>However if the table.age doesn't have at least 1 age in a category, it will just flat out ignore that case in the result. Like such:
  <img src="https://i.stack.imgur.com/n72nd.png" alt="enter image description here"></p>
  
  <p>This data set didnt have any records for age &lt; 18. So the ageband "&lt;18" doesnt show up. How can I make it so it does show up and return a value 0??</p>