rmrps
rmrps

Reputation: 85

One Hour Record in Mysql

Hi Friends i am new one for mysql I am having six column in table name time_manage the name of the column is id,date,price1,price2,price3,date_time i want to get average of price1,price2 and sum of price3 records from every one hour record in a current date that is per day totally 24 records i have the following records

 id         date    price1  price2   price3   date_time
22013   2015-01-21   2.2     1.3      4.5    (2015-01-21 00:02:05)
22013   2015-01-21   1.7     1.4      7.8    (2015-01-21 00:06:05)
22013   2015-01-21   1.5     1.2      7.6    (2015-01-21 00:58:05)
22013   2015-01-21   2.2     1.3      4.5    (2015-01-21 01:02:05)
22013   2015-01-21   1.7     1.4      7.8    (2015-01-21 01:06:05)
22013   2015-01-21   1.5     1.2      7.6    (2015-01-21 01:58:05)
22013   2015-01-21   2.2     1.3      4.5    (2015-01-21 02:02:05)
22013   2015-01-21   1.7     1.4      7.8    (2015-01-21 02:06:05)
22013   2015-01-21   1.5     1.2      7.6    (2015-01-21 02:58:05)

form above records i have to get three records from three hours record that is average of price1,price2 and sum of price3 from first three records is one row of output and average of price1,price2 and sum of price3 from record 4 to 6 is second row of output and average of price1,price2 and sum of price3 from record 7 to 9 is third row of output so totally three records from the above records like that i want to get 24 records in a current date(24 hours) please give me the guidance to get the records using mysql

Upvotes: 2

Views: 59

Answers (1)

Arun
Arun

Reputation: 760

I suspect you just want something like:

SELECT SUM(price1),SUM(price2),SUM(price3) FROM table
GROUP BY HOUR(date_time);

Upvotes: 1

Related Questions