Django:GROUP BY两个值 [英] Django: GROUP BY two values
本文介绍了Django:GROUP BY两个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我基本上希望与此问题相同 ,但是通过两个值的组合进行分组,而不仅仅是一个:
I would basically like to do the same as this question, but grouping by combinations of two values, rather than just one:
SELECT player_type, team, COUNT(*) FROM players GROUP BY player_type, team;
我使用1.2。
推荐答案
Player.objects.values('player_type', 'team').order_by().annotate(Count('player_type'), Count('team'))
这篇关于Django:GROUP BY两个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文