title: Rails aggregate query counting rows that satisfy certain conditions
body: <p>Let's say that have a table called bets.  I want to run an aggregate sql query that counts rows satisfying certain conditions.  For example, I want to return a count of all bets won, all bets lost, etc.  I also want these counts to be grouped by several different columns.  I tried a few different queries, but not getting the results I'd expect.  For example:</p>
  
  <pre><code>Bet.select("user_id, event_id, bet_line_id, pick, COUNT(state = 'won') AS bets_won,
  COUNT(state = 'lost') AS bets_lost, COUNT(state = 'pushed') AS bets_pushed").
  group('user_id, event_id, bet_line_id, pick')
  </code></pre>
  
  <p>Just gives me the result of "1" for bets_won or bets_lost or bets_pushed for any of the records returned.  Using Rails 3.2 + postgres.</p>