我有一个观点,返回 6 列
Select DataSourceName,StartedDateTime, StoppedDateTime ,
LastStateName, ErrorString , ProtectionGroup
from [dbo].[vw_RPT_BackupJobsSummaryLast24Hours]
数据返回方式如下
但我想要一个额外的行(在屏幕截图下方)按 DataSourceName 分组并基于 LastStateName(成功或失败)。 如何实现?
我尝试了以下方法,但我需要一些帮助。
select DataSourceName, StartedDateTime, StoppedDateTime , LastStateName, ErrorString
from
(
select DataSourceName, StartedDateTime, StoppedDateTime, LastStateName, ErrorString
from [dbo].[vw_RPT_BackupJobsSummaryLast24Hours]
union
select DataSourceName, 'Over All Status', case when LastStateName ='Success' then 'Success' else 'Failure' end as Value, '', ''
from [dbo].[vw_RPT_BackupJobsSummaryLast24Hours]
group by DataSourceName
) a
我已经这样解决了
select DataSourceName, StartedDateTime, StoppedDateTime , LastStateName, ErrorString
from
(
select DataSourceName, StartedDateTime, StoppedDateTime, LastStateName, ErrorString
from [dbo].[vw_RPT_BackupJobsSummaryLast24Hours]
union
select DataSourceName, 'Over All Status', case when LastStateName ='Success' then 'Success' else 'Failure' end as Value, case when LastStateName ='Success' then 'Success' else 'Failure' end as Value, ''
from [dbo].[vw_RPT_BackupJobsSummaryLast24Hours]
group by DataSourceName, LastStateName
) a