Ask a PHP + MySQL efficient algorithm for average monthly averaging

Source: Internet
Author: User
A statistical table of blood pressure is to be done recently.

For example, the database is this:
UserID Sys Dia PUL time
----------------------------------------------------
User1 88 90 78 time stamp
User2 93 100 90 Time stamp
........
........
.......
--------------------------------------------------

Now you want to average the data for the one-month period. There are three averages:

one is sys,
One is Dia,
One is Pul;


That's what I was thinking. If there is more than one measurement data per day. That requires the average of this data. If there is no measurement data on this day. Just ignore it! It is the average of each day that is counted. The average year is about averaging every month's data! Suddenly felt this complicated. Because it is the average daily data. Back to the client. How to use the database pressure is not too big! Very worried about the number of users. What happened! I beg you to support the big weapon! Thank you!


Reply to discussion (solution)

The database provides an averaging function avg

What you need, just ask the database what to do. Do not worry about whether the database can withstand, so-called personnel do not suspect

Doing a cache, caching for 5 seconds, can reduce the pressure on the database.

This need not worry, you this demand is not so big to MySQL can not do!
You just have to think about how to deal with this business!

This need not worry, you this demand is not so big to MySQL can not do!
You just have to think about how to deal with this business!


3q

Doing a cache, caching for 5 seconds, can reduce the pressure on the database.



What's good about caching?

The database provides an averaging function avg

What you need, just ask the database what to do. Do not worry about whether the database can withstand, so-called personnel do not suspect


Thank you! If you get a form that specializes in keeping average monthly and annual averages in the database. Is that necessary?

Form?
You can actually make a view so that you don't have to calculate when you query

Memcache,

Form?
You can actually make a view so that you don't have to calculate when you query



Need to return the data to the mobile app side! Is this method feasible?

Memcache,



Baidu a bit. It seems powerful.

Of course, for the Martians, they can.

Of course, for the Martians, they can.



Still don't understand how that view was made.

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.