Group by min and average FROM_UNIXTIME MYSQL

0

I have the following query:

SELECT DATE_FORMAT(FROM_UNIXTIME(history.clock), "%Y") as year, DATE_FORMAT(FROM_UNIXTIME(history.clock), "%m") as month, DATE_FORMAT(FROM_UNIXTIME(history.clock), "%d") as day, DATE_FORMAT(FROM_UNIXTIME(history.clock), "%H") as hour, DATE_FORMAT(FROM_UNIXTIME(history.clock), "%i") as min, 'value'
FROM 'history' 
WHERE  FROM_UNIXTIME(history.clock) > (FROM_UNIXTIME(1531864807) - INTERVAL 1 HOUR) 
AND FROM_UNIXTIME(history.clock) < (FROM_UNIXTIME(1531864807))

history.clock is a timestamp value, which I transform to get the different parts of a date year, month day, etc with its value then I do a where to get a range in my bd in 1 hour intervals ,

I need to group these dates with their value every 5 min and get your probe average using this:

SELECT DATE_ADD(DATE_FORMAT(FROM_UNIXTIME(history.clock),"%Y"), INTERVAL (ROUND(MINUTE(FROM_UNIXTIME(clock))/5)*5) MINUTE) year,
        DATE_ADD(DATE_FORMAT(FROM_UNIXTIME(history.clock),"%m"), INTERVAL (ROUND(MINUTE(FROM_UNIXTIME(history.clock))/5)*5) MINUTE) month,
        DATE_ADD(DATE_FORMAT(FROM_UNIXTIME(history.clock),"%d"), INTERVAL (ROUND(MINUTE(FROM_UNIXTIME(history.clock))/5)*5) MINUTE) day,
        DATE_ADD(DATE_FORMAT(FROM_UNIXTIME(history.clock),"%H"), INTERVAL (ROUND(MINUTE(FROM_UNIXTIME(history.clock))/5)*5) MINUTE) hour,
        DATE_ADD(DATE_FORMAT(FROM_UNIXTIME(history.clock),"%i"), INTERVAL (ROUND(MINUTE(FROM_UNIXTIME(history.clock))/5)*5) MINUTE) min,avg(value)
group by DATE_ADD(DATE_FORMAT(FROM_UNIXTIME(clock),'%Y-%m-%d %H:00:00'), INTERVAL (ROUND(MINUTE(FROM_UNIXTIME(clock))/5)*5) MINUTE)

the result I get is the average correctly but the values of year, month, day, hour and min I get a null

Thank you very much for your attention I will be attentive to your answers

    
asked by Javier Antonio Aguayo Aguilar 14.08.2018 в 17:24
source

0 answers