title: Ruby on Rails Group by columns and sum
body: <p>I've got the following Ruby code in my Rails application:</p>
  
  <pre><code># 1
  data.pluck(:total_earnings).sum
  
  # 2
  data2 = data.select("restaurant, food_type, city, SUM(total_earnings) as total_earnings")
            .group("restaurant, food_type, city")
  
  data2.pluck("total_earnings").sum
  </code></pre>
  
  <p><code>data</code> and <code>data2</code> are ActiveRecord Relations. </p>
  
  <p>Line #1 gives me a larger value than line #2.
  I can't understand why this is the case as I'm expecting to get a <code>total_earnings</code> value for each <code>restaurant</code>, <code>food_type</code> and <code>city</code> combination. Since I'm adding up these values, aggregating the data, why am I losing values here?</p>