【问题标题】:Group by query in Django在 Django 中按查询分组
【发布时间】:2019-09-06 18:24:22
【问题描述】:

我仍然遇到同样的问题。我希望你在解决方案中合作。我想在 Django 中得到这个查询的结果。

SELECT city_name, MAX(total_places) total_places
     FROM(SELECT city city_name, COUNT(city) total_places
             FROM Places
             GROUP BY 1) t1
     GROUP BY 1;

【问题讨论】:

    标签: django


    【解决方案1】:

    如果我查看this answer,它应该是这样的:

    Places.objects.annotate(total=COUNT('city')).latest('total')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 2015-09-07
      相关资源
      最近更新 更多