mysql-php data generated per hour by month

Source: Internet
Author: User

The demand is like this.
There is a data post that is written to the data table on the hour of the hourly.
Now you need to query on a monthly basis, such as at this point (assuming the current is 11:08), then the data is from September 1 0000 to September 6 1100 of all data.

Now there are 2 questions.
1. How should the data tables be designed for this scenario?
2. If the statistics are based on a month, such as the statistics by January 2015, How should the SQL statements be written?

Now I'm doing this, I'm going to write each hour's data into Table A (the fields are Id,time,order_count, where time is the UNIX timestamp format, which is written in PHP through the Times () function), The sum of the data in table A is then written to data table B and finally queried by data table B.
Thank you in advance for the prawns.

Reply content:

The demand is like this.
There is a data post that is written to the data table on the hour of the hourly.
Now you need to query on a monthly basis, such as at this point (assuming the current is 11:08), then the data is from September 1 0000 to September 6 1100 of all data.

Now there are 2 questions.
1. How should the data tables be designed for this scenario?
2. If the statistics are based on a month, such as the statistics by January 2015, How should the SQL statements be written?

Now I'm doing this, I'm going to write each hour's data into Table A (the fields are Id,time,order_count, where time is the UNIX timestamp format, which is written in PHP through the Times () function), The sum of the data in table A is then written to data table B and finally queried by data table B.
Thank you in advance for the prawns.

You this is a relatively simple statistics bar ... Do not know the need to draw a wave map not ~,
Everybody else. Every hour of data is given to you. You don't have to go by the hour alone. Data summary,
You just have to save every hour of data.
The table structure is basically
Id,data,time
Data is the value
Time is the timestamp of the data at which point in time 小时整 , i.e.忽略分钟

The query is indexed by time.

  • 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.