I’ve looked all over and I can’t seem to find a clear solution. Sorry if I missed it.
My Problem:
I have data that is accumulated hourly and placed in table1
I want table2.metric_ to contain an average of table1.metric_ for that day.
table1 : record_key_, id_, metric_, date_
table2 : record_key_, id_, metric_, date_
to get the list of records for the day I use:
SELECT * FROM table1 t WHERE t.date_ >= DATE_SUB(NOW(),INTERVAL 1 DAY) WHERE t.id_=’id1′;
what does the INSERT query for table2 look like so that table2.metric_ is an average of the values from the table1.metric_ column for all records of id1 in table1 returned by the previous SELECT statement?
1 Answer