Heim >Datenbank >MySQL-Tutorial >Wie repliziert man die UNPIVOT-Funktionalität in MS Access?
Herausforderung: MS Access 2010 fehlt die UNPIVOT-Funktion, die in SQL Server 2005 und höher zu finden ist. In dieser Anleitung wird gezeigt, wie Sie mit den integrierten SQL-Funktionen von Access das gleiche Ergebnis erzielen.
Szenario:
Stellen Sie sich diese Tabellenstruktur vor:
ID | A | B | C | Key 1 | Key 2 | Key 3 |
---|---|---|---|---|---|---|
1 | x | y | z | 3 | 199 | 452 |
2 | x | y | z | 57 | 234 | 452 |
Das Ziel besteht darin, es in ein nicht-pivotiertes Format zu konvertieren:
ID | A | B | C | Key |
---|---|---|---|---|
1 | x | y | z | 3 |
2 | x | y | z | 57 |
1 | x | y | z | 199 |
2 | x | y | z | 234 |
1 | x | y | z | 452 |
2 | x | y | z | 452 |
Lösung:
Der UNPIVOT-Effekt kann mithilfe einer Reihe von UNION ALL
-Anweisungen innerhalb einer Access SQL-Abfrage repliziert werden:
<code class="language-sql">SELECT ID, A, B, C, [Key 1] AS Key FROM tblUnpivotSource UNION ALL SELECT ID, A, B, C, [Key 2] AS Key FROM tblUnpivotSource UNION ALL SELECT ID, A, B, C, [Key 3] AS Key FROM tblUnpivotSource;</code>
Ergebnis:
Das Ausführen dieser Abfrage für die Beispieltabelle erzeugt das gewünschte nichtpivotierte Recordset:
ID | A | B | C | Key |
---|---|---|---|---|
1 | x | y | z | 3 |
2 | x | y | z | 57 |
1 | x | y | z | 199 |
2 | x | y | z | 234 |
1 | x | y | z | 452 |
2 | x | y | z | 452 |
Das obige ist der detaillierte Inhalt vonWie repliziert man die UNPIVOT-Funktionalität in MS Access?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!