R
R
Rxd2016-02-06 17:12:05
PHP
Rxd, 2016-02-06 17:12:05

How to effectively store the history of attribute changes in the database?

There is a table in which there should be about 100 records. And for each record, it should be possible to view changes in a certain attribute (price) for the last hour, two, day, week ...
(For example: average price an hour ago ***, average for a week ***, for a month ** *)
Attribute values ​​are measured approximately once per minute. How can this be done effectively? Is it possible to avoid creating additional columns with price values ​​during the last measurements? In general, I hope for your support :)
Something like this:
bB0RxAJnk0iozKIUjD3RvQ.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan GiBSON, 2016-02-06
@gibson_dev

Create a separate table in which to store the date, product id and price. And write there either in the application or triggers

Y
Yuri, 2016-02-06
@riky

better than radish.
store there lists of all changes per hour.
ps
just keep in mind that if the price for an hour was first 100r, then 110r, then 90r and then 200r, this does not mean that the average price per hour was 125r. the duration of such periods must also be taken into account.
maybe it was so that
1 minute - 100
2 minutes - 110
3 minutes - 90
4-60 minutes - 200
total average price is about 199
although in your case it may not be critical.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question