← Backend PythonQuestion 48 of 49
What Django ORM feature lets you get "top N per group" (e.g. most expensive product per category) while handling ties and avoiding subqueries?
📘 Explanation
Window functions like Window() with Rank() or RowNumber() let you partition and rank rows within groups directly in SQL, correctly handling ties without needing subqueries. The other options describe patterns like values().first(), annotate() with Max(), or select_related() with distinct(), which either don't reliably select the top N per group or don't handle ties properly.
Related questions
- When do you use selectrelated() vs prefetchrelated() in Django?
- What types of API versioning does Django REST Framework support?
- What are the first steps to debug performance issues in Django?
- Examples of Python stdlib modules runnable as scripts (python -m ...):
- What are the standard methods in a Django REST Framework ViewSet and their corresponding HTTP methods?
← PreviousNo login needed