title: sum over a field on a query
body: <p>this should be a asked-before question, I searched but I could not find any answer on that. Sorry if it is duplicated. I have a query lets say:</p>
  
  <pre><code>my_query=session.query(Item).filter(somefilter)
  </code></pre>
  
  <p>Now, Item has a column, lets say <code>counter</code>, and I want to find the sum of this column of <code>my_query</code>.
  I can do that like this:</p>
  
  <pre><code>sum=0
  for row in query:
      sum+=row.counter
  </code></pre>
  
  <p>but I don't this this is the efficient way of doing this specially in a large database. I know that this is possible: <a href="https://stackoverflow.com/questions/11830980/sqlalchemy-simple-example-of-sum-average-min-max">sqlalchemy simple example of `sum`, `average`, `min`, `max`</a>, but this requires filtering on <code>qry</code> (borrowed from the page) which I have already given the filtered version <code>my_query</code>. I dont know if it is really more efficient to do the filtering again on top of <code>qry</code> v.s. using the for loop on <code>my_query</code>. </p>