Если я правильно понял, вам просто нужно указать дело в вашем списке выбора и в вашей группе, например, что-то вроде
select case when Name = 'Project1' then 'Project1'
when Name = 'Project2' then 'Project1'
else Name
end as NAME
.......
group by case when Name = 'Project1' then 'Project1'
when Name = 'Project2' then 'Project1'
else Name
end
, если ваш случай таков, что сейчас это Проект 1, а месяц назад был Проект2, вам может понадобиться добавить дату в выписке по делу (на всякий случай)
select case when Name = 'Project1' and TimeEnd = getdate() then 'Project1'
when Name = 'Project2' and TimeEnd = dateadd(MONTH, -1, getdate()) then 'Project1'
else Name
end as NAME
.......
group by case when Name = 'Project1' and TimeEnd = getdate() then 'Project1'
when Name = 'Project2' and TimeEnd = dateadd(MONTH, -1, getdate()) then 'Project1'
else Name
end
Это идея.
Редактировать.
Я думаю, у вас есть возможность, если они повторяются, но мне это совсем не нравится
SELECT NAME, AVG(Current Month) as Current Month, count(Sample) as Sample, min(Previous Month) as Previous Month, min(Sample2) as Sample2, min(Two Months ago) as Two Months ago,
min(Sample3) as Sample3
FROM
(
select Name ,
avg(TimeProcessing + TimeRendering + TimeDataRetrieval) / 1000 as 'Current Month' ,
isnull(count(TimeProcessing), 0) as 'Sample' ,
min(l2.[Avg_Exec_Time_Previous_Month]) as 'Previous Month' ,
isnull(min(l2.[Executions_Last_Month]), 0) as 'Sample2' ,
min(l3.[Avg_Exec_Time_Two_Months_Ago]) as 'Two Months ago' ,
isnull(min(l3.[Executions_Two_Months_Ago]), 0) as 'Sample3'
from marlin.report_execution_log l
inner join marlin.report_catalog c on l.ReportID = c.ItemID
left outer join (
select
l2.ReportID ,
(
avg(l2.TimeProcessing + l2.TimeRendering
+ l2.TimeDataRetrieval) / 1000
) as 'Avg_Exec_Time_Previous_Month' ,
count(l2.TimeProcessing) as 'Executions_Last_Month'
from
marlin.report_execution_log l2
where
TimeEnd between dateadd(MONTH, -2, getdate())
and dateadd(MONTH, -1, getdate())
group by
l2.ReportID
) l2 on l.ReportID = l2.ReportID
left outer join (
select
l3.ReportID ,
(
avg(l3.TimeProcessing + l3.TimeRendering + l3.TimeDataRetrieval) / 1000
) as 'Avg_Exec_Time_Two_Months_Ago' ,
count(l3.TimeProcessing) as 'Executions_Two_Months_Ago'
from
marlin.report_execution_log l3
where
TimeEnd between dateadd(MONTH, -3, getdate())
and dateadd(MONTH, -2, getdate())
group by
l3.ReportID
) l3 on l.ReportID = l3.ReportID
group by l.ReportID ,
Name
)
group by Name
order by 2 desc