小编gic*_*ice的帖子

SQL Server:带XML输出的两级GROUP BY

我有一个分层数据表,我试图选择作为单个分组的XML值:

列: Id, Type, SubType, SubSubType

样本数据:

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
Run Code Online (Sandbox Code Playgroud)

对于上面的数据,我想输出以下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"/> …
Run Code Online (Sandbox Code Playgroud)

sql sqlxml sql-server-2008

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

sql ×1

sql-server-2008 ×1

sqlxml ×1