title: Count group by operation for intermediate table
body: <p>I have a table generated like this</p>
  
  <pre><code>ShopItem.select("shop_items.label_id, shop_items.store_id")
  </code></pre>
  
  <p>with the cols <code>label_id: 7789, store_id: 4140</code>. Now I want to find out, for each label, how many stores belong to it. The result should be something like <code>{"label_id" =&gt; "number of stores for the label", ... }</code></p>
  
  <p>Can I anybody give me a hint how to do it?</p>
  
  <p>(the dbms I use is PostgreSQL, and I am accessing it via Rails 3.2 ActiveRecord)</p>