title: How to do this Group By Query in Django QuerySet?
body: <p>My Django Model:</p>
  
  <pre><code>class MyModel(models.Model):
      a = IntegerField()
      b = IntegerField()
  </code></pre>
  
  <p>I want to write a query set that answers the following question: "For each distinct value of <code>a</code>, what is the min, max and average value of <code>b</code>?"</p>
  
  <p>How do I do it?</p>
  
  <p>The SQL would look something like this:</p>
  
  <pre><code>SELECT a, min(b), max(b), avg(b) FROM MyModel group by a
  </code></pre>
  
  <p>But I can't figure out how to to it with the <code>aggregate</code> and <code>annotate</code> methods. All the examples in the docs show how to use those methods when you are averaging on the same variable that you are grouping on.</p>