将多行连接到列中

时间:2013-10-29 15:30:29

标签: sql sql-server xml join

我在sql中不是很好,但是我试图根据一些id将多行连接到列中。

我有一个大表,我从xml中插入值。我发布了这个xml的一部分,所以任何人都可以测试我的代码。

DECLARE @x XML = '
<Events>
<Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5650962" IsOption="1" EventType="0" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="2.2" Home_Points="-0.25" Away_Points="0.25" Away_Odds="1.676" />
    <Total Points="2.25" Over="1.658" Under="2.17" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5650962" IsOption="0" EventType="0" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <MoneyLine Home="2.6" Draw="3.25" Away="2.65" />
    <Spread Home_Odds="1.926" Home_Points="0" Away_Points="0" Away_Odds="1.962" />
    <Total Points="2.5" Over="1.943" Under="1.901" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5650962" IsOption="1" EventType="0" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="1.478" Home_Points="0.5" Away_Points="-0.5" Away_Odds="2.58" />
    <Total Points="2.75" Over="2.18" Under="1.654" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5650962" IsOption="1" EventType="0" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="1.649" Home_Points="0.25" Away_Points="-0.25" Away_Odds="2.24" />
    <Total Points="2" Over="1.431" Under="2.66" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5650962" IsOption="1" EventType="0" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="2.6" Home_Points="-0.5" Away_Points="0.5" Away_Odds="1.472" />
    <Total Points="1.75" Over="1.31" Under="3.09" />
  </Event>
  <Event DateTimeGMT="29/10/2013 00:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694776" IsOption="0" EventType="39" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="1" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="0" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="2.5" Over="1.952" Under="1.833" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="1" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="0.5" Over="1.041" Under="9.5" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="1" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="1.5" Over="1.299" Under="3.45" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="1" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="3.5" Over="3.45" Under="1.299" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="1" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="4.5" Over="6.55" Under="1.098" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="1" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="5.5" Over="12.5" Under="1.017" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694778" IsOption="1" EventType="200" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="6.5" Over="21" Under="1.005" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="0" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="0.5" Over="1.392" Under="2.8" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="1" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="1.5" Over="2.9" Under="1.37" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="1" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="2.5" Over="7" Under="1.07" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="1" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="3.5" Over="15.75" Under="1.008" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="1" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="1" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="1" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694779" IsOption="1" EventType="201" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694781" IsOption="0" EventType="19" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="1.87" Home_Points="0" Away_Points="0" Away_Odds="1.769" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694782" IsOption="0" EventType="20" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <MoneyLine Home="2" Draw="8.25" Away="1.952" />
    <Spread Home_Odds="1.833" Home_Points="0" Away_Points="0" Away_Odds="1.769" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694784" IsOption="0" EventType="65" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="29.5" Over="1.909" Under="1.741" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694786" IsOption="0" EventType="117" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <MoneyLine Home="2.65" Draw="2.75" Away="2.45" />
    <Spread Home_Odds="1.909" Home_Points="0" Away_Points="0" Away_Odds="1.769" />
    <Total Points="1.5" Over="1.606" Under="2.1" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694788" IsOption="0" EventType="141" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <MoneyLine Home="3.9" Draw="1.625" Away="3.65" />
    <Spread Home_Odds="1.909" Home_Points="0" Away_Points="0" Away_Odds="1.8" />
    <Total Points="0.5" Over="1.714" Under="1.952" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694789" IsOption="0" EventType="59" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="1.909" Home_Points="0" Away_Points="0" Away_Odds="1.909" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5713513" IsOption="0" EventType="13" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="1.769" Home_Points="0" Away_Points="0" Away_Odds="1.952" />
    <Total Points="11.5" Over="2" Under="1.769" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5713514" IsOption="0" EventType="14" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="1.8" Home_Points="0" Away_Points="0" Away_Odds="1.909" />
    <Total Points="5.5" Over="2" Under="1.741" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5719201" IsOption="0" EventType="10" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="6.5" Over="1.952" Under="1.69" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5719468" IsOption="0" EventType="11" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Total Points="0.5" Over="2.8" Under="1.351" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5654648" IsOption="0" EventType="1" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <MoneyLine Home="3.3" Draw="2" Away="3.3" />
    <Spread Home_Odds="1.917" Home_Points="0" Away_Points="0" Away_Odds="1.893" />
    <Total Points="1" Over="1.971" Under="1.8" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5654648" IsOption="1" EventType="1" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <Spread Home_Odds="1.478" Home_Points="0.25" Away_Points="-0.25" Away_Odds="2.44" />
    <Total Points="0.75" Over="1.505" Under="2.37" />
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" Sport="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" ID="5694780" IsOption="0" EventType="2" MEID="2657152">
    <Participants>
      <Participant1 Name="Getafe" Home_Visiting="Home" />
      <Participant2 Name="Athletic Bilbao" Home_Visiting="Visiting" />
    </Participants>
    <MoneyLine Home="3" Draw="2.3" Away="2.8" />
    <Spread Home_Odds="1.87" Home_Points="0" Away_Points="0" Away_Odds="1.87" />
    <Total Points="1.25" Over="1.8" Under="1.909" />
  </Event>
<Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" QAID="4423982" EventType="38" EventName="Getafe vs Athletic Bilbao">
    <Participants>
      <Participant Name="Odd">
        <Odds TypeName="Odd/Even" OddsValue="1.952" />
      </Participant>
      <Participant Name="Even">
        <Odds TypeName="Odd/Even" OddsValue="1.833" />
      </Participant>
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" QAID="4423983" EventType="60" EventName="Getafe vs Athletic Bilbao">
    <Participants>
      <Participant Name="0:0">
        <Odds TypeName="Exact Score" OddsValue="8.25" />
      </Participant>
      <Participant Name="0:1">
        <Odds TypeName="Exact Score" OddsValue="6.85" />
      </Participant>
      <Participant Name="0:2">
        <Odds TypeName="Exact Score" OddsValue="10.25" />
      </Participant>
      <Participant Name="0:3">
        <Odds TypeName="Exact Score" OddsValue="18.5" />
      </Participant>
      <Participant Name="0:4">
        <Odds TypeName="Exact Score" OddsValue="31" />
      </Participant>
      <Participant Name="0:5">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="0:6">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="0:7">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="1:0">
        <Odds TypeName="Exact Score" OddsValue="7" />
      </Participant>
      <Participant Name="1:1">
        <Odds TypeName="Exact Score" OddsValue="6.35" />
      </Participant>
      <Participant Name="1:2">
        <Odds TypeName="Exact Score" OddsValue="8.75" />
      </Participant>
      <Participant Name="1:3">
        <Odds TypeName="Exact Score" OddsValue="17.25" />
      </Participant>
      <Participant Name="1:4">
        <Odds TypeName="Exact Score" OddsValue="31" />
      </Participant>
      <Participant Name="1:5">
        <Odds TypeName="Exact Score" OddsValue="67" />
      </Participant>
      <Participant Name="1:6">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="2:0">
        <Odds TypeName="Exact Score" OddsValue="11.25" />
      </Participant>
      <Participant Name="2:1">
        <Odds TypeName="Exact Score" OddsValue="9.25" />
      </Participant>
      <Participant Name="2:2">
        <Odds TypeName="Exact Score" OddsValue="13" />
      </Participant>
      <Participant Name="2:3">
        <Odds TypeName="Exact Score" OddsValue="23" />
      </Participant>
      <Participant Name="2:4">
        <Odds TypeName="Exact Score" OddsValue="41" />
      </Participant>
      <Participant Name="2:5">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="3:0">
        <Odds TypeName="Exact Score" OddsValue="21.25" />
      </Participant>
      <Participant Name="3:1">
        <Odds TypeName="Exact Score" OddsValue="19" />
      </Participant>
      <Participant Name="3:2">
        <Odds TypeName="Exact Score" OddsValue="24.25" />
      </Participant>
      <Participant Name="3:3">
        <Odds TypeName="Exact Score" OddsValue="31" />
      </Participant>
      <Participant Name="3:4">
        <Odds TypeName="Exact Score" OddsValue="67" />
      </Participant>
      <Participant Name="4:0">
        <Odds TypeName="Exact Score" OddsValue="41" />
      </Participant>
      <Participant Name="4:1">
        <Odds TypeName="Exact Score" OddsValue="31" />
      </Participant>
      <Participant Name="4:2">
        <Odds TypeName="Exact Score" OddsValue="41" />
      </Participant>
      <Participant Name="4:3">
        <Odds TypeName="Exact Score" OddsValue="67" />
      </Participant>
      <Participant Name="4:4">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="5:0">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="5:1">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="5:2">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="6:0">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="6:1">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="7:0">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" QAID="4423985" EventType="61" EventName="Getafe vs Athletic Bilbao">
    <Participants>
      <Participant Name="1 or X">
        <Odds TypeName="Double Chance" OddsValue="1.4" />
      </Participant>
      <Participant Name="X or 2">
        <Odds TypeName="Double Chance" OddsValue="1.357" />
      </Participant>
      <Participant Name="1 or 2">
        <Odds TypeName="Double Chance" OddsValue="1.308" />
      </Participant>
    </Participants>
  </Event>
  <Event DateTimeGMT="28/10/2013 20:00:00" Branch="Soccer" BranchID="1" League="Spain - La Liga" LeagueID="10146" QAID="4423986" EventType="62" EventName="Getafe vs Athletic Bilbao">
    <Participants>
      <Participant Name="1/1">
        <Odds TypeName="Halftime/Fulltime" OddsValue="4.45" />
      </Participant>
      <Participant Name="1/2">
        <Odds TypeName="Halftime/Fulltime" OddsValue="27.5" />
      </Participant>
      <Participant Name="1/X">
        <Odds TypeName="Halftime/Fulltime" OddsValue="14" />
      </Participant>
      <Participant Name="2/X">
        <Odds TypeName="Halftime/Fulltime" OddsValue="14" />
      </Participant>
      <Participant Name="X/X">
        <Odds TypeName="Halftime/Fulltime" OddsValue="4.9" />
      </Participant>
      <Participant Name="2/1">
        <Odds TypeName="Halftime/Fulltime" OddsValue="25" />
      </Participant>
      <Participant Name="2/2">
        <Odds TypeName="Halftime/Fulltime" OddsValue="4.1" />
      </Participant>
      <Participant Name="X/1">
        <Odds TypeName="Halftime/Fulltime" OddsValue="6.4" />
      </Participant>
      <Participant Name="X/2">
        <Odds TypeName="Halftime/Fulltime" OddsValue="6" />
      </Participant>
    </Participants>
  </Event>
</Events>

我用这个查询读了这个xml

select
    T.C.value('@DateTimeGMT', 'varchar(100)') as DateTimeGMT,
    T.C.value('@Branch', 'varchar(100)') as Branch,
    T.C.value('@BranchID', 'int') as BranchID,
    T.C.value('@League', 'varchar(100)') as League,
    T.C.value('@LeagueID', 'int') as LeagueID,
    T.C.value('@IsOption', 'int') as IsOption,
    T.C.value('@EventType', 'int') as EventType,
    T.C.value('@MEID', 'int') as MEID,
    T.C.value('@QAID', 'int') as QAID,
    T.C.value('@EventName', 'varchar(500)') as EventName,
    T.C.value('(Participants/Participant1)[1]/@Name', 'varchar(100)') as Home,
    T.C.value('(Participants/Participant2)[1]/@Name', 'varchar(100)') as Away,
    T.C.value('(MoneyLine)[1]/@Home', 'varchar(5)') as [1],
    T.C.value('(MoneyLine)[1]/@Draw', 'varchar(5)') as [X],
    T.C.value('(MoneyLine)[1]/@Away', 'varchar(5)') as [2],
    T.C.value('(Spread)[1]/@Home_Points', 'float') as Spread_Home_Points,
    T.C.value('(Spread)[1]/@Home_Odds', 'float') as Spread_Home_Odds,
    T.C.value('(Spread)[1]/@Away_Points', 'float') as Spread_Away_Points,
    T.C.value('(Spread)[1]/@Away_Odds', 'float') as Spread_Away_Odds,
    T.C.value('(Spread)[1]/@Away_Odds', 'float') as Spread_Away_Odds,
    T.C.value('(Total)[1]/@Points', 'float') as Total_Points,
    T.C.value('(Total)[1]/@Over', 'float') as Lart,
    T.C.value('(Total)[1]/@Under', 'float') as Posht,
    P.C.value('@Name', 'varchar(100)') as Rubrika,
    P.C.value('(Odds)[1]/@OddsValue', 'varchar(100)') as Koefic
from @x.nodes('Events/Event') as T(C)
    outer apply T.C.nodes('Participants/Participant') as P(C)

我将此结果表放入现有表中。我的xml非常大,通常有20000行

我想要一个基于条件将行连接到列中的查询 第一个唯一ID是MEID,第二个是EventName,它等于Home + ' vs ' + Away 结果查询应该如下所示

DateGMT, MEID,Branch,Home,Away,[1],[X],[2], other columns* 其他列*是从表中生成的列Eventname = Home + ' vs ' + Away 例如,来自此xml部分的所有值

<Participant Name="0:0">
        <Odds TypeName="Exact Score" OddsValue="8.25" />
      </Participant>
      <Participant Name="0:1">
        <Odds TypeName="Exact Score" OddsValue="6.85" />
      </Participant>
      <Participant Name="0:2">
        <Odds TypeName="Exact Score" OddsValue="10.25" />
      </Participant>
      <Participant Name="0:3">
        <Odds TypeName="Exact Score" OddsValue="18.5" />
      </Participant>
      <Participant Name="0:4">
        <Odds TypeName="Exact Score" OddsValue="31" />
      </Participant>
      <Participant Name="0:5">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="0:6">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>
      <Participant Name="0:7">
        <Odds TypeName="Exact Score" OddsValue="101" />
      </Participant>

参与者名称=“0:6”,OddsValue =“8.25”是其值

所以我的结果将是

`DateGMT,        MEID,      Branch,    Home,   Away,            [1],    [X],    [2], "0:0"  ,"0:1"  ,"0:2"  ,"0:3" ...
28/10/2013 2*,   2657152,   Soccer,    Getafe, Athletic Bilbao, 2.6,    3.25,   2.65, 8.25  ,   6.85,   10.25,   18.5 ...`

有办法怎么做?

非常感谢

0 个答案:

没有答案
相关问题