title: Number of set elements in column of type SET (population count)
body: <p>I have a table declaration like</p>
  
  <pre><code>CREATE TABLE my_foos (
      id INT NOT NULL AUTO_INCREMENT,
      bars SET('one', 'two', 'three', 'four', 'five') NOT NULL
  )
  </code></pre>
  
  <p>And the values</p>
  
  <pre><code>1, ('one', 'two')
  2, ('two')
  3, ('three', 'four', 'five')
  </code></pre>
  
  <p>Now I want to select id and the <a href="http://en.wikipedia.org/wiki/Hamming_weight" rel="nofollow">population count</a> (also called Hamming weight) of bars.</p>
  
  <p>In my example</p>
  
  <pre><code>SELECT id, POPCOUNT(bars)
  FROM my_foos
  </code></pre>
  
  <p>would return</p>
  
  <pre><code>1, 2
  2, 1
  3, 3
  </code></pre>
  
  <p><strong>What do I have to do to get the population count?</strong></p>
  
  <p><sup>Please don't answer how to do this on the client side. I hope the solution will be usable in WHERE, ORDER BY, HAVING, etc. as well.</sup></p>