The design of statistical tables in CRM system

Source: Internet
Author: User

Currently doing a statistical function of CRM, it is necessary to establish related tables to store all kinds of data related to users.
For example: Statistics on the day of an employee new customers.
A statistical table was designed to store the number of customers per day for employees.
Then, when the employee adds the customer, the corresponding field in the statistics table is added 1. When deleting a customer, the corresponding field in the statistics table is reduced by 1.
This trigger adds 1 minus 1 and executes asynchronously with Swoole.

Recently, you'll need to add stats for this week, this month, this quarter, and this year.

I will "daily statistics" copy four copies, respectively, corresponding to the "Weekly statistics", "Monthly Statistics", "Quarterly Statistics", "annual statistics."
These five tables have a similar data structure.

My question now is:
1. Is this the best way to count the number of users per day with an asynchronous trigger? Is there any other better way?
2. Statistics week, month, quarter, year of the data, is from the "Daily statistics" in the calculation of good, or directly build such four tables or asynchronous trigger way to directly store relevant data good?

There is no expert can answer, thank you in this extremely

Reply content:

Currently doing a statistical function of CRM, it is necessary to establish related tables to store all kinds of data related to users.
For example: Statistics on the day of an employee new customers.
A statistical table was designed to store the number of customers per day for employees.
Then, when the employee adds the customer, the corresponding field in the statistics table is added 1. When deleting a customer, the corresponding field in the statistics table is reduced by 1.
This trigger adds 1 minus 1 and executes asynchronously with Swoole.

Recently, you'll need to add stats for this week, this month, this quarter, and this year.

I will "daily statistics" copy four copies, respectively, corresponding to the "Weekly statistics", "Monthly Statistics", "Quarterly Statistics", "annual statistics."
These five tables have a similar data structure.

My question now is:
1. Is this the best way to count the number of users per day with an asynchronous trigger? Is there any other better way?
2. Statistics week, month, quarter, year of the data, is from the "Daily statistics" in the calculation of good, or directly build such four tables or asynchronous trigger way to directly store relevant data good?

There is no expert can answer, thank you in this extremely

What is your customer volume? If millions or the following, if I do, it is possible to save a table. The table has two fields, one called, created_at one called deleted_at , all datetime types, and the two fields are indexed.

In the future when the statistics of real-time query can be, millions the following speed, and you want to check what range to check what range. With more data, adding a cache also makes it easy to solve performance problems. Get a lot of tables to make this thing too complicated.

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