title: rails - count records by value
body: <p>I am trying to group records based on a value from a column, so I can use it to display the information elsewhere.  At the moment I have this working if I specify the values in the column - </p>
  
  <pre><code>@city_count = People.select('city,count(*)').where("city in ('london', 'paris')").group(:city).count
  </code></pre>
  
  <p>This works fine if I want a list of people in London and Paris but if the city list also has Sydney, New York, Rio etc I don't want to keep adding the extra cities to the 'city in', I would like this to just find the people selected by each city.</p>
  
  <p>Does anyone know the best way of doing this?  Also if it can include NULL values as well.</p>