This is my query:
select rc.[race number] AS RaceNumber,
max(case when seqnum = 1 then title1 end) as title1,
max(case when seqnum = 1 then [precinct percent] end) as PrecintPercent,
max(case when seqnum = 1 then [candidate num] end) as Winner,
max(case when seqnum = 1 then Votes end) as WinningVotes,
max(case when seqnum = 1 then party end) as WinningParty,
max(case when seqnum = 1 then leader end) as Winner1,
max(case when seqnum = 1 then CAST(winner AS tinyint) end) as WinnerSelected,
max(case when seqnum = 1 then [leader percent] end) as WinnerPercent,
max(case when seqnum = 2 then [candidate num] end) as Loser,
max(case when seqnum = 2 then Votes end) as LosingVotes,
max(case when seqnum = 2 then party end) as LosingParty,
max(case when seqnum = 2 then leader2 end) as Loser2,
max(case when seqnum = 2 then [leader2 percent] end) as LoserPercent,
max(case when seqnum = 2 then CAST(winner AS tinyint) end) as LoserSelected
from
(
select
r.title1,
r.[precinct percent],
rc.[race number],
rc.[candidate num],
rc.[Votes],
rc.[winner],
c.[party],
r.[leader],
r.[leader percent],
r.[leader2],
r.[leader2 percent],
c.[first name],
c.[last name],
row_number() over (partition by rc.[race number] order by votes desc) as seqnum
from dbo.[RACE CANDIDATES] rc
inner join dbo.[CANDIDATE] c on rc.[candidate num] = c.[candidate number]
inner join dbo.[RACE] r
on rc.[race number] = r.[race number]
) rc
group by rc.[race number]
select rc.[race number] AS RaceNumber,
max(case when seqnum = 3 then title1 end) as title1,
max(case when seqnum = 3 then [precinct percent] end) as PrecintPercent,
max(case when seqnum = 3 then [candidate num] end) as Winner,
max(case when seqnum = 3 then Votes end) as WinningVotes,
max(case when seqnum = 3 then party end) as WinningParty,
max(case when seqnum = 3 then [first name]+[last name] end) as Winner1,
max(case when seqnum = 3 then CAST(winner AS tinyint) end) as WinnerSelected,
max(case when seqnum = 4 then [candidate num] end) as Loser,
max(case when seqnum = 4 then Votes end) as LosingVotes,
max(case when seqnum = 4 then party end) as LosingParty,
max(case when seqnum = 4 then [first name]+[last name] end) as Loser2,
max(case when seqnum = 4 then CAST(winner AS tinyint) end) as LoserSelected,
max(case when seqnum = 5 then title1 end) as title1,
max(case when seqnum = 5 then [precinct percent] end) as PrecintPercent,
max(case when seqnum = 5 then [candidate num] end) as Winner,
max(case when seqnum = 5 then Votes end) as WinningVotes,
max(case when seqnum = 5 then party end) as WinningParty,
max(case when seqnum = 5 then [first name]+[last name] end) as Winner1,
max(case when seqnum = 5 then CAST(winner AS tinyint) end) as WinnerSelected,
max(case when seqnum = 6 then [candidate num] end) as Loser,
max(case when seqnum = 6 then Votes end) as LosingVotes,
max(case when seqnum = 6 then party end) as LosingParty,
max(case when seqnum = 6 then [first name]+[last name] end) as Loser2,
max(case when seqnum = 6 then CAST(winner AS tinyint) end) as LoserSelected
from
(
select
r.title1,
r.[precinct percent],
rc.[race number],
rc.[candidate num],
rc.[Votes],
rc.[winner],
c.[party],
r.[leader],
r.[leader percent],
r.[leader2],
r.[leader2 percent],
c.[first name],
c.[last name],
row_number() over (partition by rc.[race number] order by votes desc) as seqnum
from dbo.[RACE CANDIDATES] rc
inner join dbo.[CANDIDATE] c on rc.[candidate num] = c.[candidate number]
inner join dbo.[RACE] r
on rc.[race number] = r.[race number]
) rc
group by rc.[race number]
This results in 2 query windows. I would like to know if I can get them both to be within one single query, while keeping them separate. I believe if I can split the queries in the select statement before the end, I can get the results seperated before I use a FOR XML clause. I am trying all kinds of different methods here to get this accomplsihed.
Thank You
thanks.