Frog Frog Recommendation: Solution to a Tree Type Question.

zhaozj2021-02-16  113

Frog Frog Recommendation: Solution to a Tree Type Question.

My question: 1. A sales system, with a list of agents, the table of each agent is the database structure table 1: Agent data sheet [ID] Auto number number [Lishu] Long integrity field [xiaoshoue] Long integer sales [Ticheng] Long integer commission [add_date] date / time agent add time requirements 1. Let the agent grade, point out that an agent can calculate his superior agent and subordinate agent. 2. The proportion of the proposal is determined by the sales of sales, the proportion of the sales of 2000 is 20%, and the proportion of sales between 2000 and 6000 is 25%, and the proportion of sales between 6000 and 18000. It is 30%, the proportion of sales between 18,000 to 30000 is 35%, and the proportion of sales between 30000 to 60000 is 40%, and the proportion of sales in sales over 600,000 is 45% .3. Commission is Cally, for example, the first month's sales is 2000, then his commission is 2000 * 20% = 400, then if the second month's sales is 2000, then his total sales is the first Plus the second month of 2000 2000 = 4000, because 4000 is bound to between 2000 and 6000, so his monthly proportion should be 25%, then his monthly commission is the sales of this month. 25%, is 2000 * 25% = 5004. The new sales of the lower agents should be added to the sales of his superior agent, such as the first-level agent, b is a subordinate agent, that is Secondary agents, the sales of this month is 2000, and the sales of this month is also 3000, but because B is a lower-level agent, a sales of this month is B this month's sales plus He's sales this month. 2000 3000 = 4000 But a month this month should not be 5,000 multiplication by 25%, should be his own sales 3000 * 25%, then add his lower level agent to give He added a difference between 2000 * 25% -2000 * 20%, the whole calculation A. This month should be achieved 3000 * 25% 2000 * 25% -20 00 * 20% = 5000 * 25% -2000 * 20% = 850, but a impossible only B an agent, he and its other sub-agency's commission differences are calculated. If A this month Sales of sales is 0, and the sales of B is 2000. The result of this month should be achieved by 2000 * 20% -2000 * 20% = 0, that is, if A and B are the same sales segment, a will not from B There is a difference in the difference. But A is not possible to make B a lower agent, so even if the month is 0, he has 2 lower-level agent, and each sub-agent sales is 2000, he is this month. The result is 4000 * 25% -2000 * 20% -2000 * 20% = 2005. If a agent's lower-level agent has 1 sales over 6000, then they belong to the same proportional paragraph, So there is no difference between them, but if there are 3 sub-agent sales at more than 600,000, he can borify 5% of the extra 600,000 part of these three lower-level agents. And some other Detailed request, I don't say it first, some of which 1.2.3.5 and 4 I have already realized. Mainly 4 algorithms are too difficult, I feel that I have to redesign the data structure, or if I don't even Out, the efficiency will be very slow. Let's take a look at the specific achievement of the requirements 4, there is no classic algorithm and solution, thank you for your pointing, if you really have a short time, this honication is not Due, even if the previous part is my own yourself. I am a boss of the boss, I am so grateful. I know that it is recurrent, but open the database of each agent to open many times, such performance Very poor, you should store itself in the array, then call, then open the record set of each sub-agent,

After calculation and the first recording set comparison, I am chaotic, I can't think of how many RecordSets have been established. How many times, how many times, how to update a data to two records, a lot of trouble, no hair . Is it a good implementation? I feel how to solve the stored procedure or array. My current practice is to open two database links, but this time is very wrong, it is best to Come, first open a link, take the required data, save the array. Open the second link, loop the array above, and operate. If you need to update the first link, you will finally update, the principle know, it is written I can't come out. Complicated recursive algorithms I really can't get it, especially in the for cycle, I still get a few IF nested. I don't know which state is in the end. Please ask this situation. The skills are analyzed. Below is a reply from the river.

This is a multi-level tree (Tree), in fact, the principle is similar to the structure of our forum, we are the main data structure of this to achieve [ID] long integer [NUM_REPLIED] double precision [Num_Followed] double Accuracy [NUM_LASTTIME] Double-precision type When a customer is the top: first-level customer, it should be num_replied = num_followed if it is the second-level customer should be: Num_rePlied = new time code Num_Followed = The last level number Num_Replied is also Say, secondary or non-primary classification customers should be num_replied <> num_followed and update Num_LastTime when updating Num_LastTime when a lower customer or a lower customer is added, and it is to say that the entire customer tree is complete, as long as Num_LastTime The same, must be the same principal classification, which is easy to get a complete customer tree, get the first step of the category Num_LastTime, according to two time yards, the whole tree structure is organized but the problem Yes: If we have to get all the superiors of a certain customer or all the lower levels? According to the above data structure, a customer can exist aspects of the same level of relationships, as long as he is not a primary classification, all Num_Replied is the same, and Num_LastTime is a level; but they may not belong to The same superior customers, all, the above structure cannot be directly completed, do the following changes: the data structure after the change [ID] long integer [Mark] long integer [Num_Replied] double precision [num_followed] double precision [Num_LastTime] double-precision type adds a Mark field, used to represent the number of customers, first-level customers with 0, 2nd 1 represented, according to such push ... So, give all the following levels of a customer This is the same, indicating the same level customer 2.mark> The customer's mark3.num_replied> The customer's NUM_REPLIED is here, you can find all the superiors of a customer, you should also know how to do it. If you think too much Trouble, I hope to use a field to express the affiliated relationship like your data structure. I have to learn how to scientifically and efficiently encode we can come to 32-bit binary strings to represent a customer code such as: 0111 0010 0001 0100 0111 0001 0101 0111 The front four bits used to represent the first level of customers, if it is a customer, then his back should be 0 is similar to: 0001 0000 00 00 00 00 00 00 00 00 If it is the second level Customers, the second paragraph should have a number, such as 0001 0000 0010 0000 00 00 00 00 0000 If it is one of the next level, there is also: 0001 0000 00000000 0000 0000 000 0000 like a secondary push, unfortunately this algorithm is used :

Bits and calculations, and this is not supported in VBS and Access, but unfortunately. Another 2 classic tree algorithm is in the construction of website, often requires processing of trees with tree-type data structures such as commodity classification, column classification, forum topics. If these categories are not encoded, the efficiency of the program is very low. So how do I design a highly efficient encoding algorithm? Here is a highly efficient classification algorithm. I am in many of our company's web applications, including e-commerce, download sites, news distribution systems, have applied such encoding algorithms, and the effect is very good. Problems to be resolved in the classification algorithm in the construction of the website, the application of classification algorithms is very common. When designing an electronic store, you should involve a commodity classification; when designing a publishing system, it is related to the column or channel classification; when the design software downloads such a program, it is related to the software classification; so, wait. It can be said that classification is a very common problem. I often interview some programmers, and I have no exception to ask them some questions about classification algorithms. Here's a few questions I often ask. Do you think you can answer it easily ^ _ ^. 1, classification algorithm often manifest as a tree representation and traversal problem. So, then, if you express the tree class classification with a table in the database, should there be a few fields? 2, how to quickly restore a tree from this table; 3, how to determine if a classification is another classification; 4, how to find all the products of a classification; 5, how to generate the path where the classification is located. 6, how to add classification; these problems are not easy to answer if the number of classifications of the classification and the number of classifications per level. This article tries to solve these problems. Classified data structure We know: The classified data structure is actually a tree. In the "Data Structure" course, everyone may learn TREE algorithms. Since we use the database in the construction of our website, we will talk from the storage of Tree in the database. To simplify the problem, we assume that each node only needs to reserve this information. We need to numbered each node. There are many ways to numbered. The commonly used in the database is the automatic number. This is like this in Access, SQL Server, Oracle. Suppose the number field is ID. In order to indicate a node ID1 is the parent node of another node ID2, we need to keep a field in the database, indicating which node belongs to the son. Ten this field name FatherID. As the ID2 here, its FatherID is ID1. In this way, we get the data sheet definition of Catalog Catalog: CREATE TABLE [Catalog] ([ID] [INT] NOT NULL, [NAME] [NVARCHAR] (50) Not null, [FatherId] [INT] NOT NULL); Agreement: We agree to use -1 as the top-level father code. Classification of -1. This is a virtual classification. It is not recorded in the database. How to restore the biggest advantage of the Catalog definition above a tree is that it can easily recover a tree-classification tree. To make a clearer display algorithm, we first consider a simple question: How to display the next class classification of a classification.

We know, to check the next class classification of a classification FID, the SQL statement is very simple: select name from catalog where fitherid = FID shows these categories, we simply use

  • : <% Rem Oconn - - Database connection, calling getChildren When you have opened REM FID ----- Current Classified number Function getChildren (Oconn, FID) strsql = "select id, name from catalog where fatherid =" & FID set RScatalog = Oconn.execute (strsql) %>

  • New Post(0)