Burkhard
17-01-07, 11:45
Dieses von Frau B.Hauser entlehnte und angepasste, nachstehende Beispiel nummeriert die Zeilen der Ergebnismenge.
Nun soll ein SQL erstellt werden, das je gleicher Gruppe (bestehend aus den ersten 10 Stellen von "Text") eine neue Nummerierung von 1 bis n erfolgt.
Ich bin leider nicht in der Lage, eine Lösung zu finden.
Vielleicht weiß jemand von Ihnen Rat.
Vielen Dank im Voraus.
Burkhard
with x as (select digits(TLfirm) concat ' '
concat digits(TLTOUR) concat ' '
concat digits(LRTZEI) as Text
from VDBDTAPKFT/LRHSTA02, VDBDTAPKFT/TOULZU02
where TLFIRM = LRFIRM and TLSTOR = LRSTOR and
TLABTL = LRABTL and TLLIRH = LRLIRH and TLFIRM = 1
group by TLFIRM, TLTOUR, LRTZEI),
y as (select substr(Text, 1, 15) as yText,
substr(Text, 1, 15) as yKey from x),
z as (select Text as zText,
substr(Text, 1, 15) as zkey from x)
select yText, count(ykey) as Nummer
from y join z on yKey >= zKey
group by yText
____________________________
Ergebnis ist:
YTEXT NUMMER
001 00101 01700 1
001 00110 00830 2
001 00110 01130 3
001 00110 01400 4
001 00120 00700 5
001 00120 00900 6
001 00120 01300 7
001 00130 00900 8
001 00130 01200 9
Ergebnis soll:
YTEXT NUMMER
001 00101 01700 1
001 00110 00830 1
001 00110 01130 2
001 00110 01400 3
001 00120 00700 1
001 00120 00900 2
001 00120 01300 3
001 00130 00900 1
001 00130 01200 2
Nun soll ein SQL erstellt werden, das je gleicher Gruppe (bestehend aus den ersten 10 Stellen von "Text") eine neue Nummerierung von 1 bis n erfolgt.
Ich bin leider nicht in der Lage, eine Lösung zu finden.
Vielleicht weiß jemand von Ihnen Rat.
Vielen Dank im Voraus.
Burkhard
with x as (select digits(TLfirm) concat ' '
concat digits(TLTOUR) concat ' '
concat digits(LRTZEI) as Text
from VDBDTAPKFT/LRHSTA02, VDBDTAPKFT/TOULZU02
where TLFIRM = LRFIRM and TLSTOR = LRSTOR and
TLABTL = LRABTL and TLLIRH = LRLIRH and TLFIRM = 1
group by TLFIRM, TLTOUR, LRTZEI),
y as (select substr(Text, 1, 15) as yText,
substr(Text, 1, 15) as yKey from x),
z as (select Text as zText,
substr(Text, 1, 15) as zkey from x)
select yText, count(ykey) as Nummer
from y join z on yKey >= zKey
group by yText
____________________________
Ergebnis ist:
YTEXT NUMMER
001 00101 01700 1
001 00110 00830 2
001 00110 01130 3
001 00110 01400 4
001 00120 00700 5
001 00120 00900 6
001 00120 01300 7
001 00130 00900 8
001 00130 01200 9
Ergebnis soll:
YTEXT NUMMER
001 00101 01700 1
001 00110 00830 1
001 00110 01130 2
001 00110 01400 3
001 00120 00700 1
001 00120 00900 2
001 00120 01300 3
001 00130 00900 1
001 00130 01200 2