Home > database >  Table 3 queries for bosses
Table 3 queries for bosses

Time:09-17

Bosses, a list of all level 3, such as user 1 invite users to 2, then users 1 is 2 supervisors, user 2 inviting users to 3, so users 1 is 3 on the superior
Now I want to also get all of my superior data on users to the superior, but there are primary empty won't display, bosses how to write, please

CodePudding user response:

You can refer to the mysql recursive query:

SELECT ID level, DATA. * FROM (
SELECT
@ ids as _ids,
(SELECT @ ids:=GROUP_CONCAT (id)
The FROM table1
WHERE FIND_IN_SET (parent_id, @ ids)
) as cids,
@ : l=@ l + 1 as level
The FROM table1,
(SELECT @ ids:='1', @ : l=0) b
WHERE @ ids IS NOT NULL
Table1) id DATA
WHERE FIND_IN_SET (DATA. Id, id. _ids)
The ORDER BY level, id
  • Related