我有下表:
我有这个问题:
Select StartDate, SubscriptionGUID,
(Select sum(TotalExistingDBHoursInPeriod)
from dbo.SQLDBBusinessKPIDB_Snap
where [Platform] = 'SAWA') as "SAWA Contrib"
FROM dbo.SQLDBBusinessKPIDB_Snap
返回以下结果:
我想要的是" SAWA Contrib"要仅为SubscriptionGUID
行的总和,它当前返回[Platform] = "SAWA"
任何指针都会很棒!
答案 0 :(得分:3)
向内部查询添加约束,如:
Select so.StartDate, so.SubscriptionGUID,
(Select sum(TotalExistingDBHoursInPeriod)
from dbo.SQLDBBusinessKPIDB_Snap si
where si.[Platform] = 'SAWA' and si.SubscriptionGUID = so.SubscriptionGUID) as "SAWA Contrib"
FROM dbo.SQLDBBusinessKPIDB_Snap so