我正在寻找一种可能的方法来消除子查询。
任何评论都会有所帮助
SELECT
[FacilityGroupID]
,[LocationGroupID]
,[MsrID]
,CAST(LEFT([ReportingPeriod],4) + '-'
+ RIGHT([ReportingPeriod],2)
+ '-01' as datetime) as create_timestamp
,SUM([Denominator]) as [Denominator]
,SUM([Numerator]) as [Numerator]
FROM
(
SELECT
DISTINCT
Tob.FacilitygroupId
,Tob.LocationgroupId
,Tob.Reportingperiod
,Tob.Denominator
,DimIndicator.MsrId
,CASE
WHEN DimIndicator.MsrID = Tob.MsrId THEN 1
ELSE 0
END as Numerator
from
BIReport.dbo.vIndianatest "Tob"
INNER JOIN [BIreport].[dbo].[DimIndicator] "DimIndicator"
on Tob.MsrSubGroupId = DimIndicator.MsrSubGroupId
) as "Inner"
GROUP BY
[FacilityGroupID]
,[LocationGroupID]
,[MsrID]
,CAST(LEFT([ReportingPeriod],4) + '-'
+ RIGHT([ReportingPeriod],2)
+ '-01' as datetime)
与子查询一样,性能太慢了。
谢谢 !!!