Django equivalent of COUNT with GROUP BY

If you are using Django 1.1 beta (trunk):

Player.objects.values('player_type').order_by().annotate(Count('player_type'))
  • values('player_type') – for inclusion only player_type field into GROUP BY clause.
  • order_by() – for exclusion possible default ordering that can cause not needed fields inclusion in SELECT and GROUP BY.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)