Home > database >  SQL query statistics about the tree structure, solving!!!!!!
SQL query statistics about the tree structure, solving!!!!!!

Time:09-18

A statistical query requirements, SQL statements don't know how to write, please master solution:
The table below:
Select * from jd_tree a; - directory tree
+ -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
| jd_dm | jd_mc | fjd_dm | can_deep | jb_dm |
+ -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
The root directory of | 1000000001 | | NULL | Y | 001 |
1010000001 | 1 | 1000000001 | | 001001 | Y | directory
1020000001 | 2 | 1000000001 | | 001002 | Y | directory
1030000001 directory | 3 | | 1000000001 | | 001003 | N
| 1010000001 | | 1010100001 | catalog 1-1 N 001001001 | |
| 1010200001 | catalog 1-2 | 001001002 | | 1010000001 | N
1-3 | 1010000001 | | 1010300001 | directory N | 001001003 |
| 1020000001 | | 1020100001 | catalog 2-1 N 001002001 | |
2-2 | | 1020200001 | directory 1020000001 | 001002002 | | N
2-3 | 1020000001 | | 1020300001 | directory N | 001002003 |
1020400001 | | directory | 1020000001 | | 001002004 | Y 2-4
The 1020400001 | 2-4-1 | | 1020401001 | directory N | 001002004001 |
The 1020400001 | 2-4-2 | | 1020402001 | directory N | 001002004002 |
+ -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
Select * from jd_djl b; - click
+ -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
| jd_dm | DJL |
+ -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
| 1020402001 | |
| | 1010100001 | 1
| | 1010200001 | 1
+ -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
Have two forms jd_tree and jd_djl, jd_tree jb_dm is that, in turn, add back in the table can be used to like
Now at the front desk and a parameter jd_dm (jd_dm value of jd_tree list), according to the front desk parameters passed
1) such as front desk parameters passed the corresponding can_deep='Y', shows his next level of various views;
2) such as front desk parameters passed the corresponding can_deep='N', shows the jd_dm hit
Example 1: such as passed in 1000000001, should be to display the following
| jd_dm | jd_mc | DJL |
Directory | 1010000001 | 1 | 2
2 | | 1020000001 | catalog 5
Directory | 1030000001 | 3 | 0
Example 2: if passed in 1030000001, should show as follows,
| jd_dm | jd_mc | DJL |
Directory | 1030000001 | 3 | 0

CodePudding user response:

What version of mysql?

CodePudding user response:

reference 1st floor stelf response:
what version of mysql?

Casually which version is fine, as long as it can write the statement
  • Related