Select extreme values of a certain range in MySQL

0

I need to collect only the extreme 'id' values for each given time range. According to the data below, I need to collect the ids 63 and 67 for the time of 00:45:22, 80 and 84 for the time of 01:15:26. How to proceed?

id   n  hora          data      AP

63  5   00:45:22    24/05/2017  3  
64  5   00:45:22    24/05/2017  1  
65  5   00:45:22    24/05/2017  3  
66  5   00:45:22    24/05/2017  3  
67  5   00:45:22    24/05/2017  3  
80  5   01:15:26    24/05/2017  5  
81  5   01:15:26    24/05/2017  5  
82  5   01:15:26    24/05/2017  5  
83  5   01:15:26    24/05/2017  5  
84  5   01:15:26    24/05/2017  5  
    
asked by anonymous 07.07.2017 / 20:01

1 answer

1

MAX and GROUP BY

select hora , min(id) min_id , max(id) max_id
from tabela
group by hora 
GROUP BY is used when you want to use aggregators such as sum, count, average, standard deviation, maximum and minimum, can also be used for deletion of duplicates, I always recommend a read in the documentation of the DBMS vendor for details.

    
07.07.2017 / 23:20