SELECT date, name, MAX(broom) GROUP BY name; 如何向DjangoORM提交此请求?我意识到答案将以dict的形式出现,但最终我只得到了名为'name‘和'broom__max’的字段,如何在其中添加'date‘?class Brooms(models.Model): broom = model
我在DjangoORM中使用.annotate()和.aggregate()时遇到了问题。, max(date_time) as max_date GROUP BY group_id
) as s on m.group_id=s.group_idand m.date_time=s.max_date 它返回: ----------------------------------------
一些使用GROP BY和SUM DjangoORM trable进行了如下查询:
"SELECT "p_record"."h", SUM("p_record"."size") AS "size__sum" FROM "p_record" GROUP BY "p_record"."h", "p_record"."Django
class ItemGroup(models.Model): group = models.ForeignKey(ItemGroup, on_delete=models.CASCADE在SQL中,我将左联接用于此目的:
SELECT item_group.name, COUNT(*) as item_cou