← Fullstack with Vue.jsQuestion 49 of 62
What's the difference between annotate() vs values().annotate() in Django ORM?
📘 Explanation
annotate() alone adds a computed value per object without grouping, while values().annotate() groups rows by the specified fields and computes aggregates per group via SQL GROUP BY. The wrong answers misstate this relationship, claiming restrictions on aggregation functions or reversing which one performs grouping and which doesn't.
Related questions
- What does Django's extra() method do, and when would you use it?
- When you call selectrelated("author") on a Book queryset, what kind of SQL join does Django generate? Does it always…
- When is annotate() guaranteed to generate a GROUP BY in Django ORM?
- When do you use selectrelated() vs prefetchrelated() in Django?
- What Django ORM feature lets you get "top N per group" (e.g. most expensive product per category) while handling ties…
← PreviousNo login needed