Я пытаюсь объединить два запроса, оба запроса сгруппированы по разным полям. Если я запускаю оператор SELECT из запроса, он дает мне правильные данные, но если я запускаю весь запрос, он дает мне нулевое значение
Select A.Year,
A.NewProjects,
A.InactiveCancelled,
B.CompletedProject
from
(select year(ts.ReceptionDate) as Year,
Count(ts.ID)as ID,
count(*) as NewProjects,
count(case when ts.status = 'Inactive' then 1
when ts.status = 'Cancelled' then
1 end ) as InactiveCancelled
from rpt.transmissionservicesrpt ts
Where ts.Type = 'Retail / Utility POI' and
ts.ReceptionDate > '12-31-2011'
group by year(ts.receptiondate)) A
Inner Join
(Select year(tsr.CompletedProject) as Year,
Count(tsr.TSRID) as TSRID,
count(case when tsr.Status = 'Completed'
then 1 end ) as CompletedProject
from [rpt].
[TSRRetailUtilityHistoricalWorkloadView] tsr
where tsr.Type = 'Retail / Utility POI' and
tsr.CompletedProject > '12-31-2011'
group by year(tsr.CompletedProject)) B on
A.ID = B.TSRID
/****************New Project & Incomplete
Projects***************************/
select
year(ts.ReceptionDate) as Year,
count(*) as NewProjects,
count(case when ts.status = 'Inactive' then 1
when ts.status = 'Cancelled' then 1 end )
as InactiveCancelled
from rpt.transmissionservicesrpt ts
Where ts.Type = 'Retail / Utility POI' and ts.ReceptionDate > '12-31-
2011'
group by year(ts.receptiondate)
order by year(ts.receptiondate);
/****************Completed Project***************************/
Select year(tsr.CompletedProject) as Year,
count(case when tsr.Status = 'Completed' then 1
end ) as CompletedProject
from
[rpt].[TSRRetailUtilityHistoricalWorkloadView] tsr
where tsr.Type = 'Retail / Utility POI' and tsr.CompletedProject > '12-
31-2011'
group by year(tsr.CompletedProject)
order by year(tsr.CompletedProject);
Year Inactive Completed
2012 1 1
2013 6 5
2014 25 16
2015 39 24
2016 46 24
2017 22 12
2018 58 30
2019 168 22