Ask a php + mysql efficiency algorithm for average monthly and annual-php Tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.