Home  >  Article  >  Backend Development  >  How do you do statistics on such data?

How do you do statistics on such data?

WBOY
WBOYOriginal
2016-08-04 09:19:06961browse

I have a store clerk management system. The clerk has 1W, which is called members. The clerk has a recommendation mechanism (the clerk can recommend almost unlimited levels).
There is also a sales performance table of the clerk, member_sales. Every time a clerk makes a sale, a piece of data will be written to member_sales.
Now I have to count the daily turnover of a clerk and all his subordinate clerks every day. If he meets my performance requirements, I will give him a bonus.
There is not much data now. I opened 5 crontabs to count 2,000 shop assistants every hour, and the job was completed in 5 hours.
But I’m afraid that when there are more store employees, this stupid method won’t work anymore. What should I do?

Reply content:

I have a store clerk management system. The clerk has 1W, which is called members. The clerk has a recommendation mechanism (the clerk can recommend almost unlimited levels).
There is also a sales performance table of the clerk, member_sales. Every time a clerk makes a sale, a piece of data will be written to member_sales.
Now I have to count the daily turnover of a clerk and all his subordinate clerks every day. If he meets my performance requirements, I will give him a bonus.
There is not much data now. I opened 5 crontabs to count 2,000 shop assistants every hour, and it took 5 hours to complete.
But I’m afraid that when there are more store employees, this stupid method won’t work anymore. What should I do?

Use a database, mysql is simple enough

Use the database to make statistics on the data. Maybe you can do data analysis later

Just run once every morning in the early morning. It’s not necessary to run every hour.

Are you using a database? sqlThere can be only 2,000 queries per hour. What specific tasks does crontabdo?

A relational database of this magnitude is perfect

There should be something wrong with the SQL you are counting. Is there a loop select embedded in it?

Do it again. There was something wrong with the tree structure design of the clerk, and the statistical logic was wrong, so it took too long and couldn't be explained in a few dozen sentences.
The clerk must have a tree structure, and his sales performance is the sum of the sales performance of himself and all his sub-nodes.
In addition, the member_sales table should have two fields: sales date and sales time. The sales date is used for statistics, and the date cannot be converted by formatting the sales time.
The tree structure can refer to unlimited classifications.

Post all the SQL and programs for your scheduled tasks and take a look

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn