Hello, I started this rather messy draft (outline of how I think it could be approached), as I posted this ticket [1] some years ago. Basically, SQL adds some modifiers to group the result set in different ways. The ticket contains some links with good examples.
In order to solve this, it seems necessary to make a method that bypasses the group by logic of Django, so expert users can handle this themselves. Most likely, users who want to use this feature, are already more familiar with how a database works, than Django deals with GROUP BY quite well, so the name may be poorly chosen, because seasoned database people starting off with Django may be tempted to neglect this fact, and jump straight off to that method, not reading the admonition. There's already get_group_by_cols which may be considered as well. I left a flag in the draft, Query.custom_group_by but haven't thought this through. I think it should be manageable for me to work on getting subquery (I posted another thread 2-3 weeks ago) and a custom grouping method introduced in Django 3.2. [1] https://code.djangoproject.com/ticket/27646 -- Med venlig hilsen / Kind regards, Mads Jensen -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/A6DC48D3554543B2BC0DBB8D175F90A7.MAI%40webhot.dk.