MySQL is divided into tables by month. how does PHP perform Summary Statistics Query, sorting, and paging?

Source: Internet
Author: User
Requirement background group table group chat record table is sharded by month, for example, the region table structure chatTimemessage time groupID group ID requirement description is given a time period, such as the last 7 days of the current day when... requirement background group table

Group

Chat record table

Table sharding by month, such

Chat_message_2015_04

Chat_message_2015_05

Chat_message_2015_06

Table structure

ChatTime // message time
GroupID // group ID

Requirement description
  1. Specify a time period, for example, the current day, the last 7 days, the current month, and the latest month ~ , Count the number of messages of each group in a given period of time
  2. Sort the group and output it by page based on the number of statistics.

Reply content: requirement background group table

Group

Chat record table

Table sharding by month, such

Chat_message_2015_04

Chat_message_2015_05

Chat_message_2015_06

Table structure

ChatTime // message time
GroupID // group ID

Requirement description
  1. Specify a time period, for example, the current day, the last 7 days, the current month, and the latest month ~ , Count the number of messages of each group in a given period of time
  2. Sort the group and output it by page based on the number of statistics.

1,UNION
2. if innodb sub-tables are used, merge can be used for processing.

Directly create a summary table for statistics

If possible, do not use the table sharding design. in this way, no special processing is required for queries. If you plan the index, the performance should be normal.

Related Article

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.