私は、コストセンタ、ベンダ、ツール、コスト、および四半期の列を持つテーブルを持っています。私はと2四半期(たとえば15/16 Q3および15/16 Q2)とのコスト差の結果を取得したい:私は最初に以下のようにCOSTCENTERとベンダーのために結果を取得するクエリを作成しているテーブルに複数のクエリを結合して1つの選択結果を得る
select a.Costcenter,c.Vendor,(SumA-SumB) as costcenter_diff, (SumC-SumD) as vendor_diff from
(select Costcenter ,sum(CostTotal) as SumA
from Rawdata
where Quarter='15/16 Q3'
group by Costcenter)as a,
(select Costcenter,sum(CostTotal) as SumB
from Rawdata
where Quarter='15/16 Q2'
group by Costcenter) as b
Join
(select Costcenter,Vendor,sum(CostTotal) as SumC
from Rawdata
where Quarter='15/16 Q3'
group by Costcenter,Vendor)as c,
(select Costcenter,Vendor,sum(CostTotal) as SumD
from Rawdata
where Quarter='15/16 Q2'
group by Costcenter,Vendor) as d where a.Costcenter = b.Costcenter and
c.Costcenter= d.Costcenter and c.Vendor= d.Vendor;
ご質問はもう少し明確にしてください。私は2四半期の間にコスト差の結果を得たいと思っています(例えば、Q3は15/16、Q2は15/16)。 Q3? Q2? –
また、あなたの質問を画像ではなくテキストとして質問に入れてください。 –
Q3は第3四半期、第2四半期は2015-16年の第2四半期です。私は、これらの四半期間のコスト差をCostcenterとVendorに賢明に求めています。私はSumAとして'15/16Q3 '、SumBを'15/16Q2'として2つのコストを選択し、コストセンターのために最初のSELECTで(SumA-SumB)を減算し、同様にベンダーに対しても同様のコストを選択します。しかし、私は上のスナップショットで述べたような形で出力を得ることができません。 – user6559913