Bratmaxxe
04-02-09, 06:11
Hallo SQL'er,
habe ein Problem. Gegeben ist nachfolgende Tabellenstruktur:
http://www.bild-upload.net/bild.php/7871,tables4CHBG.jpg
Tabelle 1 (MYC4REP):
C4RCTX, C4D0NB, C4LFDN sind Primärschlüssel
Tabelle 2 (MYC5REP):
C5RCTX, C5D0NB, C5LFDN, C5CRNB, C5W3NB, C5W4NB, C5XXTX sind Primärschlüssel
Tabelle 3 (MWI5REP):
I5RCTX, I5D0NB, I5CRNB, I5W3NB, I5W4NB, I5XXTX sind Primärschlüssel
Tabelle 1 stellt einen Kopfsatz dar.
Tabelle 2 ist die dazugehörige Positionstabelle (Verknüpfung aus Tabelle 1 und 3).
Tabelle 3 (eigentliche Datentabelle)
In einer Java Anwendung möchte ich nun folgende Informationen darstellen:
Aus Tabelle 1:
C4LFDN und die Bezeichnung (Spalte hinter C4LFDN)
Aus Tabelle 2:
Min und Max C5W4NB
Anzahl der Datensätze aus Tabelle 2 die zu einer Kopfposition C4LFDN gehören
Aus Tabelle 3:
Anzahl der Datensätze die als Attribut ein 'J' aufweisen (Spalte I5NFO1 nicht im Screenshot enthalten).
Beispiel mit C4LFDN = 1
Darzustellende Informattion:
1(c4lfdn aus Tabelle 1) ma (text aus Tabelle 1) 1220(min C5W4NB aus Tabelle 2) 1380(max C5W4NB aus Tabelle 2) 4(Anzahl Datensätze aus Tabelle2) 2(Anzahl derer, die in Tabelle 3 ein 'J' aufweisen)
Soweit bin ich schon gekommen:
SELECT MYC4REP.*,
(SELECT MIN(C5W4NB) FROM MYC5REP WHERE C4RCTX = C5RCTX AND C4D0NB = C5D0NB AND C4LFDN = C5LFDN) AS MIN_C5W4NB,
(SELECT MAX(C5W4NB) FROM MYC5REP WHERE C4RCTX = C5RCTX AND C4D0NB = C5D0NB AND C4LFDN = C5LFDN) AS MAX_C5W4NB,
(SELECT COUNT(*) FROM MYC5REP WHERE C4RCTX = C5RCTX AND C4D0NB = C5D0NB AND C4LFDN = C5LFDN) AS ANZ_IN_TABELLE_2
FROM MYC4REP
WHERE MYC4REP.C4RCTX = '100' AND MYC4REP.C4D0NB = 676 ORDER BY C4RCTX
mir fehlt nur noch die Anzahl der Datensätze aus Tabelle 3, wo bei I5NFO1 ein 'J' vorhanden ist...
Wie bekomme ich die da mit rein ?
Würde mich über eine Hilfe freuen,
VlG
Bratmaxxe
habe ein Problem. Gegeben ist nachfolgende Tabellenstruktur:
http://www.bild-upload.net/bild.php/7871,tables4CHBG.jpg
Tabelle 1 (MYC4REP):
C4RCTX, C4D0NB, C4LFDN sind Primärschlüssel
Tabelle 2 (MYC5REP):
C5RCTX, C5D0NB, C5LFDN, C5CRNB, C5W3NB, C5W4NB, C5XXTX sind Primärschlüssel
Tabelle 3 (MWI5REP):
I5RCTX, I5D0NB, I5CRNB, I5W3NB, I5W4NB, I5XXTX sind Primärschlüssel
Tabelle 1 stellt einen Kopfsatz dar.
Tabelle 2 ist die dazugehörige Positionstabelle (Verknüpfung aus Tabelle 1 und 3).
Tabelle 3 (eigentliche Datentabelle)
In einer Java Anwendung möchte ich nun folgende Informationen darstellen:
Aus Tabelle 1:
C4LFDN und die Bezeichnung (Spalte hinter C4LFDN)
Aus Tabelle 2:
Min und Max C5W4NB
Anzahl der Datensätze aus Tabelle 2 die zu einer Kopfposition C4LFDN gehören
Aus Tabelle 3:
Anzahl der Datensätze die als Attribut ein 'J' aufweisen (Spalte I5NFO1 nicht im Screenshot enthalten).
Beispiel mit C4LFDN = 1
Darzustellende Informattion:
1(c4lfdn aus Tabelle 1) ma (text aus Tabelle 1) 1220(min C5W4NB aus Tabelle 2) 1380(max C5W4NB aus Tabelle 2) 4(Anzahl Datensätze aus Tabelle2) 2(Anzahl derer, die in Tabelle 3 ein 'J' aufweisen)
Soweit bin ich schon gekommen:
SELECT MYC4REP.*,
(SELECT MIN(C5W4NB) FROM MYC5REP WHERE C4RCTX = C5RCTX AND C4D0NB = C5D0NB AND C4LFDN = C5LFDN) AS MIN_C5W4NB,
(SELECT MAX(C5W4NB) FROM MYC5REP WHERE C4RCTX = C5RCTX AND C4D0NB = C5D0NB AND C4LFDN = C5LFDN) AS MAX_C5W4NB,
(SELECT COUNT(*) FROM MYC5REP WHERE C4RCTX = C5RCTX AND C4D0NB = C5D0NB AND C4LFDN = C5LFDN) AS ANZ_IN_TABELLE_2
FROM MYC4REP
WHERE MYC4REP.C4RCTX = '100' AND MYC4REP.C4D0NB = 676 ORDER BY C4RCTX
mir fehlt nur noch die Anzahl der Datensätze aus Tabelle 3, wo bei I5NFO1 ein 'J' vorhanden ist...
Wie bekomme ich die da mit rein ?
Würde mich über eine Hilfe freuen,
VlG
Bratmaxxe