Motivation:
You search for an efficient approach that finds top N rows of every group.
Note:
If you are not familiar with the ROW_NUMBER() window function then consider reading How to efficiently assign a database temporary sequence of values to rows before continuing.
Description:
This application is an example of finding top N rows of every group via the ROW_NUMBER() window function.
Key points:
Write a native query relying on ROW_NUMBER() window function as in the code below:
Testing time:
Tam Ta Da Dam! :) The complete application is available on GitHub.
If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices".
Comments