Guest User

Untitled

a guest
Oct 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. SELECT cat, dog, bird, count(1) FROM animals WHERE master_id = 1 GROUP BY cat, dog, bird
  2.  
  3. animals = Animals.objects.filter(id=1).values('cat', 'dog', 'bird').annotate(ct=Count('cat'), dg=Count('dog'), br=Count('bird'))
  4.  
  5. Animals.objects.filter(
  6. master_id=1
  7. ).values('cat', 'dog', 'bird').annotate(
  8. ct=Count('id')
  9. ).order_by('cat', 'dog', 'bird')
  10.  
  11. <QuerySet [
  12. { 'cat': 0, 'dog': 2, 'bird': 1, 'ct': 1 },
  13. { 'cat': 0, 'dog': 3, 'bird': 3, 'ct': 4 },
  14. { 'cat': 1, 'dog': 0, 'bird': 0, 'ct': 2 },
  15. { 'cat': 2, 'dog': 2, 'bird': 1, 'ct': 5 },
  16. ]>
Add Comment
Please, Sign In to add comment