Ask a php + mysql efficiency algorithm to calculate the average monthly per year to prepare a blood pressure statistical table recently.
For example, the database is like this:
Userid sys dia pul time
----------------------------------------------------
User1 88 90 78 timestamp
User2 93 100 90 timestamp
........
........
.......
--------------------------------------------------
Now we need to calculate the average of the data in a month. There are three averages:
One is sys,
One is dia,
One is pul;
I think so. If the measurement data is measured multiple times a day. That requires the average of this data. If there is no measurement data for this day. Ignore it! That is, the monthly average is the average of each day. The annual average is to average the data of each month! I suddenly think this is complicated. Because it is the average daily data. Back to the client. how can I use the database! I am very worried about the large number of users. What is the situation! Thank you for your support! Thank you!
Reply to discussion (solution)
The database provides the avg function with an average value.
What you need is what the database does. Don't worry about whether the database can afford it.
A cache of 5 seconds can reduce the pressure on the database.
You don't have to worry about this. your demand is not so huge that mysql can't do it!
You just need to think about how to handle this business!
You don't have to worry about this. your demand is not so huge that mysql can't do it!
You just need to think about how to handle this business!
3q
A cache of 5 seconds can reduce the pressure on the database.
What is a good introduction to caching?
The database provides the avg function with an average value.
What you need is what the database does. Don't worry about whether the database can afford it.
Thank you! If you create a table in the database that stores the monthly and annual averages. Is this necessary?
Form?
In fact, it can be made into a view so that no computing is required during the query.
Memcache,
Form?
In fact, it can be made into a view so that no computing is required during the query.
Data needs to be returned to the mobile app! Is this method feasible?
Memcache,
Baidu. It seems very powerful.
Yes, of course.
Yes, of course.
I still don't know how that view is created.
Select avg (sys), avg (dia), avg (pul), substr (sqltime, 0, 8) as tips from table group by tips