PERSNR | NAME | PERSNR#CHEF |
1 | Obermotz 1 | <null> |
2 | Obermotz 2 | <null> |
3 | Obermotz 3 | <null> |
11 | Mittelmotz 11 | 1 |
12 | Mittelmotz 12 | 1 |
13 | Mittelmotz 13 | 1 |
21 | Mittelmotz 21 | 2 |
22 | Mittelmotz 22 | 2 |
23 | Mittelmotz 23 | 2 |
31 | Mittelmotz 31 | 3 |
32 | Mittelmotz 32 | 3 |
33 | Mittelmotz 33 | 3 |
111 | Untermotz 111 | 11 |
112 | Untermotz 112 | 11 |
113 | Untermotz 113 | 11 |
114 | Untermotz 114 | 11 |
121 | Untermotz 121 | 12 |
122 | Untermotz 122 | 12 |
123 | Untermotz 123 | 12 |
211 | Untermotz 211 | 21 |
212 | Untermotz 212 | 21 |
213 | Untermotz 213 | 21 |
311 | Untermotz 311 | 31 |
312 | Untermotz 312 | 31 |
313 | Untermotz 313 | 31 |
321 | Untermotz 321 | 32 |
1111 | Roedldoedl 1111 | 111 |
1112 | Roedldoedl 1112 | 111 |
1113 | Roedldoedl 1113 | 111 |
1114 | Roedldoedl 1114 | 111 |
1121 | Roedldoedl 1121 | 112 |
1122 | Roedldoedl 1122 | 112 |
1211 | Roedldoedl 1211 | 121 |
1212 | Roedldoedl 1212 | 121 |
1231 | Roedldoedl 1231 | 123 |
1232 | Roedldoedl 1232 | 123 |
1311 | Roedldoedl 1311 | 131 |
1312 | Roedldoedl 1312 | 131 |
2111 | Roedldoedl 2111 | 211 |
2112 | Roedldoedl 2112 | 211 |
2113 | Roedldoedl 2113 | 211 |
3111 | Roedldoedl 3111 | 311 |
3112 | Roedldoedl 3112 | 311 |
3311 | Roedldoedl 3311 | 331 |
3211 | Roedldoedl 3211 | 321 |
PERSNR | NAME | PERSNR#CHEF |
11 | Mittelmotz 11 | 1 |
12 | Mittelmotz 12 | 1 |
13 | Mittelmotz 13 | 1 |
WITH ABCDE ( PERSNR , NAME ) AS | -- feste Syntax für Common table expression, Spaltenliste lt. Frage 1 |
( SELECT PERSNR, NAME FROM ORGA WHERE PERSNR#CHEF = 1 | -- Basisselect lt. Frage 2 |
UNION ALL | -- feste Syntax für Rekursion |
SELECT A.PERSNR , A.NAME FROM ORGA A | -- Spaltenliste (wie gehabt lt. Frage 1) |
INNER JOIN ABCDE B ON A.PERSNR#CHEF = B.PERSNR ) | -- Rekursionsbedingung lt. Frage 3 |
SELECT * FROM ABCDE; | -- der letzendliche Select |
PERSNR | NAME |
11 | Mittelmotz 11 |
12 | Mittelmotz 12 |
13 | Mittelmotz 13 |
111 | Untermotz 111 |
112 | Untermotz 112 |
113 | Untermotz 113 |
114 | Untermotz 114 |
121 | Untermotz 121 |
122 | Untermotz 122 |
123 | Untermotz 123 |
131 | Untermotz 131 |
1111 | Roedldoedl 1111 |
1112 | Roedldoedl 1112 |
1113 | Roedldoedl 1113 |
1114 | Roedldoedl 1114 |
1121 | Roedldoedl 1121 |
1122 | Roedldoedl 1122 |
1211 | Roedldoedl 1211 |
1212 | Roedldoedl 1212 |
1231 | Roedldoedl 1231 |
1232 | Roedldoedl 1232 |
1311 | Roedldoedl 1311 |
1312 | Roedldoedl 1312 |
PERSNR | NAME | STUFE |
1 | Obermotz 1 | 1 |
11 | Mittelmotz 11 | 2 |
12 | Mittelmotz 12 | 2 |
13 | Mittelmotz 13 | 2 |
111 | Untermotz 111 | 3 |
112 | Untermotz 112 | 3 |
113 | Untermotz 113 | 3 |
114 | Untermotz 114 | 3 |
121 | Untermotz 121 | 3 |
122 | Untermotz 122 | 3 |
123 | Untermotz 123 | 3 |
1111 | Roedldoedl 1111 | 4 |
1112 | Roedldoedl 1112 | 4 |
1113 | Roedldoedl 1113 | 4 |
1114 | Roedldoedl 1114 | 4 |
1121 | Roedldoedl 1121 | 4 |
1122 | Roedldoedl 1122 | 4 |
1211 | Roedldoedl 1211 | 4 |
1212 | Roedldoedl 1212 | 4 |
1231 | Roedldoedl 1231 | 4 |
1232 | Roedldoedl 1232 | 4 |
PERSNR | NAME | PERSNR#CHEF |
1121 | Roedldoedl 1121 | 112 |
112 | Untermotz 112 | 11 |
11 | Mittelmotz 11 | 1 |
1 | Obermotz 1 | - |
Zurück zu DB2 | Home | Impressum / Datenschutz |