examerioLogin
← 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

← PreviousNo login needed