Putting all the information into maximum and minimum tables, still trying to fix the comparation method for grouping rows