Table ( members )
-----------------
ID Full_Name Recommended_By Direction Node
1 Name1 None
2 Name2 1 Left (1)
3 Name3 1 Right (1)
4 Name4 2 Left (2)(1)
5 Name5 3 Left (3)(1)
6 Name6 2 Left (2)(1)
7 Name7 3 Right (3)(1)
以下のスクリプトを実行すると、最初に 1 つの ID (1) だけが返されますが、すべての ID が必要です。
ID Node Left_Direction Right_Direction Recommended_By
2 (1) Name2 1
3 (1) Name3 1
4 (2)(1) Name4 2
5 (3)(1) Name5 3
6 (2)(1) Name6 2
7 (3)(1) Name7 3
select a.ID,a.Node,
(case when (a.Direction = 'Left') then a.Full_Name else '' end) AS `Left_Direction`,
(case when (a.Direction = 'Right') then a.Full_Name else '' end) AS `Right_Direction`,
a.Recommended_By
from
members a
WHERE
CONCAT("'%(",a.ID,")%'") in ( SELECT b.Node From members b)
AND
a.Node IS NOT NULL or trim(a.Node) <> ''
GROUP BY a.ID