How To Efficiently Distribute The Number Of Rows In The Specified (N) Number Of Groups Via NTILE(N)
Description: This application is an example of distributing the number of rows in the specified (N) number of groups via the window function, NTILE(N)
. This window function is available in almost all databases, and starting with version 8.x is available in MySQL as well.
Key points:
- commonly, you don't need to fetch in the result set the temporary ranking of values produced by
NTILE()
(you will use it internally, in the query, usually in theWHERE
clause and CTEs), but, this time, let's write a Spring projection (DTO) that contains a getter for the column generated byNTILE()
as well - write several native querys relying on
NTILE()
window function