开发者

group by multiple fileds and order by count of group in python/django

开发者 https://www.devze.com 2023-03-18 03:00 出处:网络
Please help me in getting the result of below in django/python开发者_JAVA百科 SELECT u,v,x,y,z,count(1) FROM table1 group byu,v,x,y,z order by5,6;

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')
0

精彩评论

暂无评论...
验证码 换一张
取 消