Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SQL Rekursion

Empfohlene Antworten

Veröffentlicht

Hallo,

ich habe eine MySQL Datenbank mit folgende Tabellen:

-------------------------

ORDNER | ELTERN | KIND

-------------------------

root......| NULL ... | 1

a_1.......| 1 ....... | 2

a_2.......| 1 ....... | 3

a_3.......| 1 ....... | 4

b_1.......| 2 ....... | 5

b_2.......| 2 ....... | 6

b_3.......| 2 ....... | 7

c_1.......| 4 ....... | 8

d_1.......| 3 ....... | 55

d_2.......| 3 ....... | 122

Es siet ungeführ so aus:

root_

...... | - a_1 _

.................. | - b_1

.................. | - b_2

.................. | - b_3

...... | - a_2 _

.................. | - d_1

.................. | - d_2

............................................ // also hier können mehrere Unterordner kommen, oder Unter - Unterordner und soweiter.

...... | - a_3 _

.................. | - c_1

Wie kann ich eine Rekursive SQL-Abfrage aufbauen, damit man für einen Ordner (z.B a_2) alle Unterordner bekommt?

Es können aber beliebig viele unter - unter Ordner in d_1 und d_2 ect. sein. Also die Verschachtelung ist nicht vorhersehbar!

Geht meines wissens nicht.

Für diese Situation gibt es das Nested Set Modell.

Status Quo - develnet.org

Gruß Jaraz

aus www.is.informatik.uni-duisburg.de/courses/dbp_ss05/material/woche07.pdf



WITH rek (stueck, komponente, menge) AS (

SELECT r.stueck, r.kompenente, r.menge

FROM bauteile r

WHERE r.stueck = 'Beispiel-Bauteil'

UNION ALL

SELECT kind.stueck, kind.komponente, kind.menge

FROM rek vater,

bauteile kind

WHERE vater.komponente = kind.stueck

)

SELECT DISTINCT stueck, komponente, menge

FROM rek

ORDER BY stueck, komponente, menge

Aber keine Ahnung ob das mit jeder SQL Variante und jedem DBMS funktioniert

In IBM DB2 geht es auf jeden Fall

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.