php - [id pid] type table data, obtain the number of all sub-teams for each id, the data volume is more than 2W.
高洛峰
高洛峰 2017-05-16 13:01:11
0
1
1018

There is a data table of type [id pid], as follows:

--- id --- pid ---
--- A --- B ---
--- A --- C ---
--- B --- D ---
--- B --- E ---
--- C --- F ---
--- C --- G ---

Corresponding structure:

-D
        -E
    -B
A
    -C
        -F
        - G

How to count the number of subordinate teams of A, B, C, D, E, F, G (including yourself).
For example

id number of teams
A 7
B 3
C 3
D 1
E 1
F 1
G 1

Currently, I take out all the data and obtain such data through recursion. If there are subordinates, I count the number of teams recursively.

Problems encountered:
When the data volume reaches 2W, all data is taken out, causing the memory to be full
Do you have any good solutions?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
给我你的怀抱

Counting step by step, there is no need to take out the entire tree at once;
In addition, the path can be recorded for each node; for statistics, just count (*) like '%A%', for example, to find the number of descendants of A

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template