title: Django group_by argument depending on order_by
body: <p>I'm struggling (again) with Django's annotate functionality where the actual SQL query is quite clear to me.</p>
  
  <p><strong>Goal:</strong></p>
  
  <p>I want to get the number of users with a certain let's say <code>status</code> (it could be just any column of the model).</p>
  
  <p><strong>Approach(es):</strong></p>
  
  <p>1) <code>User.objects.values('status').annotate(count=Count('*'))</code></p>
  
  <p>This results into the following SQL query</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT users_user.status, COUNT(*) as count
  FROM users_user
  GROUP BY users_user.id
  ORDER BY usser_user.id ASC
  </code></pre>
  
  <p>However, this will give me a queryset of all users each "annotated" with the count value. This is kind of the behaviour I would have expected.</p>
  
  <p>2)  <code>User.objects.values('status').annotate(count=Count('*')).order_by()</code></p>
  
  <p>This results into the following SQL query</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT users_user.status, COUNT(*) as count
  FROM users_user
  GROUP BY users_user.status
  </code></pre>
  
  <p>No <code>ORDER BY</code>, and now the <code>GROUP BY</code> argument is the <code>status</code> column. This is not what I expected, but <strong>the result I was looking for</strong>.</p>
  
  <p><strong>Question</strong>:
  Why does Django's <code>order_by()</code> without any argument affect the SQL <code>GROUP BY</code> argument? (Or broader, why does the second approach "work"?)</p>
  
  <p><em>Some details</em>:</p>
  
  <ul>
  <li>django 2.2.9</li>
  <li>postgres 9.4</li>
  </ul>