Aggregations on explicit GROUP BY queries
See original GitHub issueIs your feature request related to a problem? Please describe. Currently, it is not possible to group entries by a specific field to apply aggregations. A raw SQL example would be:
SELECT AVG(gpa)
FROM students
WHERE age > 21
GROUP BY gender
Describe the solution you’d like
To keep the API similar to Django’s, it would be nice to be able to use annotate()
on ValuesQuery
:
Student.filter(age__gt=21).values('gender').annotate(average_gpa=Avg('gpa'))
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
SQL GROUP BY - Everything You Need To Know - Sisense
This clause is most often used with aggregations to show one value per grouped field or combination of fields. Consider the following table:...
Read more >5 Practical SQL Examples To Master SQL GROUP BY
In SQL, GROUP BY is used for data aggregation, using aggregate functions. such as SUM() , MIN() , MAX() , AVG() and COUNT()...
Read more >Implicit vs. Explicit Grouping (Aggregates) - Mailing lists - W3C
When we surveyed existing approaches to aggregates at the F2F[1], the majority of implementations required that groups be explicitly defined ...
Read more >GROUP BY (Transact-SQL) - SQL Server | Microsoft Learn
A SELECT statement clause that divides the query result into groups of rows, usually by performing one or more aggregations on each group....
Read more >SQL Group By Tutorial: Count, Sum, Average, and Having ...
This is how the GROUP BY clause works. First we define how we want to group the rows together—then we can perform calculations...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Meh,
gpa
,age
,bunny
I’ts all the same. 🤓Honestly, I find Django one of the better ORMs in the Python world. There is a lot of care put into most of the spec. It’s mostly consistent, and we can do a lot worse than copy parts of it. The interface is already quite different, and was from day one. We could have tried and made it match closer, but some of the uglier parts are there mostly due to legacy reasons. Also, Django does a lot more than just ORM.
Hi, I released 0.16.9 and it should have the change for this issue.
Could you please test and confirm?