作成しようとしている SQL Server 2012 クエリを特定するのに苦労しており、誰かが助けてくれることを願っています。これは私が現在クエリとして持っているものです:
--home wins
select NULL as roadlosses, Count(t1.TeamName) as homewins, t1.TeamName from scores s
inner join games g
on g.GameID=s.GameID
inner join teams t1
on t1.TeamID=g.HomeTeam
inner join teams t2
on t2.Teamid=g.AwayTeam
where (s.hometotalruns - s.awaytotalruns) > 0 and t1.TeamName = 'Pirates'
group by t1.teamname
UNION
--road losses
select Count(t2.TeamName) as roadlosses, NULL, t2.TeamName from scores s
inner join games g
on g.GameID=s.GameID
inner join teams t1
on t1.TeamID=g.HomeTeam
inner join teams t2
on t2.Teamid=g.AwayTeam
where (s.hometotalruns - s.awaytotalruns) > 0 and t2.TeamName = 'Pirates'
group by t2.TeamName
これにより、結果は次のようになります。
roadlosses homewins teamname
NULL 41 Pirates
26 NULL Pirates
これで sを削除して 1 行のみを返したいNULL
のですが、取得できないようです。
これを見てみましたが、私が必要としているものとはまったく異なります。