Hallo Christian,
ich habe ein Problem mit einer Tabelle, die ich gerne folgendermaßen verändern möchte.
Vorher:
ID | Typ1 | Anteil | Typ_2 | Anteil_2 | Typ_3 | Anteil_3
0 | A | 50 | B | 40 | C | 10
1 | A | 50 | B | 40 | D | 10
2 | B | 50 | D | 50 | |
3 | A | 60 | D | 40 | |
4 | C | 100 | | | |
5 | D | 60 | E | 20 | F | 20
das sieht traurigerweise nach einer falschen Tabellenstruktur aus.
Für weitere Typen und Anteile nimmt man eben _nicht_ weitere Spalten.
Nachher:
ID | Typ | Anteil
0 | A | 50
0 | B | 40
0 | C | 10
1 | A | 50
1 | B | 40
1 | D | 10
2 | B | 50
2 | D | 50
3 | A | 60
...Weiß jemand, ob das irgendwie mit der Funktion TRANSFROM geht?
Nein, das geht nicht mit der TRANSFORM, das geht mit UNION
SELECT
ID,
Typ1 AS Typ,
Anteil
FROM tabelle
UNION ALL
SELECT
ID,
Typ_2,
Anteil_2
FROM tabelle
UNION ALL
SELECT
ID,
Typ_3,
Anteil_3
FROM tabelle
liefert Dir Dein gewünschtes Resultat.
Allerdings rate ich Dir dringend, Deine Tabellenstruktur zu überdenken.
Freundliche Grüße
Vinzenz