Mysql
 sql >> Database >  >> RDS >> Mysql

Valori minimi e massimi di MySQL e data corrispondente per ogni mese

Prova questa query, il nome del database è test, puoi usare il tuo o rimuoverlo:

SELECT 
  MIN(rate) AS minRate,
  (select date from test.rates where rate = min(co.rate) and  
    month(date) = month(co.date) and year(date) = year(co.date) limit  
  )as min_date,
  MAX(rate) AS maxRate,
  (select date from test.rates where rate = max(co.rate) and  
    month(date) = month(co.date) and year(date) = year(co.date) limit 1) as 
  max_date
FROM test.rates co 
GROUP BY year(date) , month(date)