title: SQL - counting rows with specific value
body: <p>I have a table that looks somewhat like this:</p>
  
  <pre><code>id  value
  1   0
  1   1
  1   2
  1   0
  1   1
  2   2
  2   1
  2   1
  2   0
  3   0
  3   2
  3   0
  </code></pre>
  
  <p>Now for each <code>id</code>, I want to count the number of occurences of 0 and 1 and the number of occurences for that ID (the value can be any integer), so the end result should look something like this:</p>
  
  <pre><code>id  n0  n1  total
  1   2   2   5
  2   1   2   4
  3   2   0   3
  </code></pre>
  
  <p>I managed to get the first and last row with this statement:</p>
  
  <pre><code>SELECT id, COUNT(*) FROM mytable GROUP BY id;
  </code></pre>
  
  <p>But I'm sort of lost from here. Any pointers on how to achieve this without a huge statement?</p>