Hi, thanks for the reply! This gives me following query:
SELECT "example_price"."category_id", "example_price"."cost" FROM "example_price" GROUP BY "example_price"."id", "example_price"."category_id", "example_price"."from_date", "example_price"."cost", "example_price"."period" HAVING "example_price"."from_date" = (MAX("example_price"."from_date")) It's not quite right. Is there a way to have different fields in the SELECT and in the GROUP BY? Regards, Artem. On Wednesday, October 17, 2018 at 4:04:04 PM UTC+3, v.kiselicy...@gmail.com wrote: > > Price.objects.annotate(_sel=Max('from_date')).filter(from_date=F('_sel')).values("category_id", > > "price") > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2902f2f5-1733-4f16-b831-6eebee8e0a3c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.