question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aggregations on explicit GROUP BY queries

See original GitHub issue

Is 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:open
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
grigicommented, Mar 22, 2020

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.

0reactions
grigicommented, Apr 26, 2020

Hi, I released 0.16.9 and it should have the change for this issue.

Could you please test and confirm?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found