group by multiple fileds and order by count of group in python/django
Please help me in getting the result of below in django/python
开发者_JAVA百科SELECT u,v,x,y,z,count(1) FROM table1 group by u,v,x,y,z order by 5,6;
Not sure what you mean by order by 5,6
, I assume you have columns with that name...
Anyway, it should work like this:
results = MyModelForTable1.objects.values('u', 'v', 'x', 'y', 'z').annotate(Count('u')).order_by('5', '6')
精彩评论