title: SQL count occurrences of certain categories that rows belong to
body: <p>I have this table with some data:</p>
  
  <pre><code>table ColorsFlavors
  
  id | name | color | flavor
  --------------------------
   1 | n1   | green | lemon
   2 | n2   | blue  | strawberry
   3 | n3   | red   | lemon
   4 | n4   | green | lemon
   5 | n5   | green | mango
   6 | n6   | red   | chocolate
   7 | n7   | white | lemon
   8 | n8   | blue  | mango
   9 | n9   | green | chocolate
  </code></pre>
  
  <p>I wish to make a SQL query (or queries?) that lets me get the total number of rows with each color, and the total number of rows with each flavour.</p>
  
  <p>Something like this:</p>
  
  <pre><code>colors | occurrences
  --------------------
  green  |   4
  blue   |   2
  red    |   6
  white  |   1
  
  
  flavor    | occurences
  ----------------------
  lemon     |   4
  strawberry|   1
  mango     |   2
  chocolate |   2
  </code></pre>
  
  <p>Uhmmm what about too if I have a predefined list of colors and flavors to pick from, so that colors/flavors that don't occur on the data table get a 0 count?</p>
  
  <pre><code>colors | occurrences
  --------------------
  green  |   4
  blue   |   2
  red    |   6
  white  |   1
  black  |   0
  
  
  flavor    | occurences
  ----------------------
  lemon     |   4
  strawberry|   1
  mango     |   2
  chocolate |   2
  cherry    |   0
  </code></pre>
  
  <p>So, what would be the SQL queries to retrieve those?</p>