页: 1
它希望
1 | N | 1
2 | 1 | 1/2
3 | 2 | 1/2/3
4 | 3 | 1/2/3/4
5 | 3 | 1/2/3/5
6 | 2 | 1/2/6
7 | 6 | 1/2/6/7
8 | 2 | 1/2/8
9 | 1 | 1/9
10 | 9 | 1/9/10
11 | 10 | 1/9/10/11
12 | 11 | 1/9/10/11/12
13 | 11 | 1/9/10/11/13
14 | 11 | 1/9/10/11/14
15 | 14 | 1/9/10/11/14/15
16 | 14 | 1/9/10/11/14/16
17 | 14 | 1/9/10/11/14/17
18 | 10 | 1/9/10/18
19 | N | 19
20 | 19 | 1920
21 | 19 | 1921
我需要根据本表提出一些问题。
The queries I need to do are
Select all children of
id
9
SELECT * FROM `tester` WHERE path LIKE %/9/% ;
罚款。 在您以1或19条取代该身份证之前,先没有<代码>/。
SELECT * FROM `tester` WHERE path LIKE %1/% ;
选择1、1、11、21、31、211等数字结尾的所有行文
SELECT * FROM `tester` WHERE path LIKE 1/% ;
第1行或第19行将正确运作
So SELECT * FROM
testerWHERE path LIKE 1/% OR path LIKE %/1/%
;
Is the best I can come up with, any suggestions?
Select Direct children of 9 but not sub-children
For this
Select * from
testerwhere parent = 9
; will work fine.
select an aggregate count of 9 s children, x levels deep.
因此,在结束发言时,我要提到代表不同层次的<条码>第1级、第2级、第3级、第......级x/<条码>或x行,
Let us pretend x is 3 for this example
The rows from this example would be 9, 8, 6
(the 4th level if we requested it would be 3)
任何想法?
<><>Edit>/strong>
#select count of children of specific node(5) down to a maximum of three levels, do no include the parent
SELECT COUNT(child.id) children,
LENGTH(REPLACE(child.path, parent.path, )) - LENGTH(REPLACE(REPLACE(child.path, parent.path, ), / , )) AS LEVEL
FROM `tester` child JOIN `tester` parent ON child.path LIKE CONCAT(parent.path, % )
WHERE parent.id =5
GROUP BY LEVEL HAVING LEVEL <= 3 AND LEVEL > 0;
**select 9 s children s id s down to x levels, with the level relative to 9,
因此,我们再一次将使用3×。
我们正期待着退席。
10 | 1
11 | 2
18 | 2
12 | 3
13 | 3
14 | 3
我再次对如何做到这一点感到完全损失。
Edit:
#select all information, and relative level from parent of children of specific node(5) down to a maximum of three levels, do no include the parent
SELECT child.*,
LENGTH(REPLACE(child.path, parent.path, )) - LENGTH(REPLACE(REPLACE(child.path, parent.path, ), / , )) AS LEVEL
FROM `tester` child JOIN `tester` parent ON child.path LIKE CONCAT(parent.path, % )
WHERE parent.id =9
GROUP BY id HAVING LEVEL <= 3 AND LEVEL > 0;