我試圖在查詢數據庫時生成以下XML。該數據庫 包含兩個表COUNTRY和美國 -用於生成XML結果的SQL查詢
<Country>
<CountryInfo>
<name>USA</name>
<districts>50</districts>
<state>
<stateName>New York</stateName>
<statePop>8,244,910</statePop>
</state>
<state>
<stateName>Chicago</stateName>
<statePop>State Population: 2,707,120</statePop>
</state>
</CountryInfo>
<CountryInfo>
<name>Germany</name>
<districts>16</districts>
<state>
<stateName>Berlin</stateName>
<statePop>3,469,910</statePop>
</state>
<state>
<stateName>Brandenburg</stateName>
<statePop>2,500,000</statePop>
</state>
</CountryInfo>
</Country>
下面是一個嘗試 -
select ctry.NAME, ctry.DISTRICTS, st.ST_NAME, st.ST_POPULATION
from COUNTRY ctry inner join STATES st on (ctry.NAME=st.COUNTRY);
結果是一個平面文件。
<CountryCollection>
<COUNTRY>
<NAME>USA</NAME>
<DISTRICTS>50</DISTRICTS>
<ST_NAME>New York</ST_NAME>
<ST_POPULATION>8,244,910</ST_POPULATION>
</COUNTRY>
<COUNTRY>
<NAME>USA</NAME>
<DISTRICTS>50</DISTRICTS>
<ST_NAME>CHICAGO</ST_NAME>
<ST_POPULATION> 2,707,120</ST_POPULATION>
</COUNTRY>
<COUNTRY>
<NAME>GERMANY</NAME>
<DISTRICTS>16</DISTRICTS>
<ST_NAME>Berlin</ST_NAME>
<ST_POPULATION>3,469,910</ST_POPULATION>
</COUNTRY>
<COUNTRY>
<NAME>GERMANY</NAME>
<DISTRICTS>50</DISTRICTS>
<ST_NAME>Brandenburg</ST_NAME>
<ST_POPULATION>2,500,000</ST_POPULATION>
</COUNTRY>
</CountryCollection>
我該如何對它們進行分組以獲得所需的結果?
您使用的是什麼RDBMS? –
RDBMS是Oracle – proximityFlying