SQL Server: Dwupoziomowy GROUP BY z wyjściem XML
Mam tabelę hierarchicznych danych, które próbuję wybrać jako pojedynczą zgrupowaną wartość XML:
Kolumny:Id, Type, SubType, SubSubType
Przykładowe dane:
Id Type Subtype SubSubType
1 Product Documentation Brochures Functional Brochures
2 Product Documentation Brochures Fliers
3 Product Documentation Data Sheets and Catalogs Data Sheets
4 Product Documentation Data Sheets and Catalogs Catalogs
5 Other Documentation Other classification User Guides
Dla powyższych danych chciałbym wypisać następujące xml:
<AllTypes>
<Type name="Product Documentation">
<SubType name="Brochures">
<SubSubType name="Functional Brochures"/>
<SubSubType name="Fliers"/>
</SubType>
<SubType name="Data Sheets and Catalogs">
<SubSubType name="Data Sheets"/>
<SubSubType name="Catalogs"/>
</SubType>
</Type>
<Type name="Other Documentation">
<SubType name="Other classification">
<SubSubType name="User Guides"/>
</SubType>
</Type>
</AllTypes>
tj. pojedyncza struktura XML zawierająca wszystkie wiersze z powyższej tabeli, pogrupowana według pierwszej kolumny (Typ), a następnie pogrupowana według drugiej kolumny (Podtyp).