Id=25, tier=1, parent_id=0, pids=null,
How to implement the update tier, and pids, realize the display effect,
Pids=parent_id + parent_id pids;
Tier sequence number for the current data structure
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Tier pids parent_id id
2 25 25 26
3, 26, 25, 26 and 27
3, 26, 25, 26, 28
3, 26, 25 and 34
3, 25 26 36
3, 25 26 47
3, 25 26 89
3, 25 26 95
3, 25 26 99
3, 25 26 102
3, 25 26 105
3, 25 26 109
3, 25 26 112
3, 25 26 127
3, 25 26 151
4,26,25 27 29
4,26,25 27 30
4,26,25 27 31
4,26,25 27 32
April 27,26,25 27 to 33
4,26,25 27 35
4,26,25 27 37
4,26,25 27 38
28 April 28,26,25 39
4 34,26,25 40
4 34,26,25 43
4,26,25 27 44
4 36,26,25 36 45
4 36,26,25 36 46
4,26,25 27 49
4,26,25 27 50
4 36,26,25 36 55
4 34,26,25 58
4 34,26,25 59
4,26,25 27 61
4,26,25 27 69
4 36,26,25 36 70
4 34,26,25 34 81
4 34,26,25 34 86
4,26,25 27 90
4 34,26,25 34 92
4,26,25 27 100
4 34,26,25 34 108
4 34,26,25 34 113
4 34,26,25 34 115
4 34,26,25 34 117
4 34,26,25 34 124
4 34,26,25 34 125
4,26,25 27 126
4,26,25 27 133
4 34,26,25 34 148
4 34,26,25 34 149
4,26,25 27 154
4,26,25 27 155
April 27,26,25 27, 169
CodePudding user response:
The UPDATE
` level ` l1
LEFT the JOIN ` level ` l2 ON l1. The parent_id=l2. Id
Set l1. Pids=the if (ISNULL (l2) id), ' ', the if (l2) pids=', l1. The parent_id, CONCAT (l1 parent_id, 'and' l2. Pids))), l1. Tier=the if (ISNULL (l2) id), 1, l2. The tier + 1)
WHERE 1;
How many times how many levels is executed,
A statement directly, the efficiency is very low
CodePudding user response:
Upstairs,