【发布时间】:2018-03-09 19:01:58
【问题描述】:
This is the image of the table and output required with details
所以,我写了一个 Django 查询
ModelClassName.objects.values('houseid','vehid').annotate(Count('vehid')).order_by('houseid')
这是给我每辆 vehid 的计数,但由于我不确定如何在此处合并 Max,我无法获得正确的结果。 任何帮助都是可观的。 谢谢。
【问题讨论】:
-
使用当前代码,你得到了什么输出?你能在这里通过查询集吗?
-
这不是我写的例子,而是我得到的实际查询集
-
我没有看到带有注释本身的解决方案,我可以建议一些 SQL 替代方案吗?或者这个查询集的逻辑?
-
那太好了。
标签: django count max aggregate annotate