Get the max of each partition in SQL