title: Must appear in Group By clause or used in agg. function
body: <p>I have a large User table and I'm trying to group all users within a town by street and get a count via postgres &amp; rails.  The following gives me the right data however I'm wondering if I could get a better output:</p>
  
  <pre><code>User.group(:town,:street).count ###Gives a large hash of key/value pairs with town_name repeated each time for every grouped street like {['TOWN_NAME', 'STREET_NAME']=&gt;'#ofUsers'}
  </code></pre>
  
  <p>So instead of this: <code>{['BETHPAGE', 'JACKSON AVE']=&gt;372, ['BETHPAGE', 'WILLIAM ST']=&gt;28}</code></p>
  
  <p>I'd like <code>{ 'BETHPAGE'=&gt;{['JACKSON', 372],['WILLIAM ST', 28]} }</code></p>
  
  <p>Is there a better query that would output this information in a format that the TOWN_NAME would be used once as a key and each street and its count are given in an array like:</p>
  
  <pre><code>{ 'TOWN_NAME' =&gt; {['STREET_NAME', '#ofUsers'], ['STREET_NAME', '#ofUsers']}
  </code></pre>