我正在尝试对我刚刚在查询中创建的两个 CASE 函数求和。我需要这两列在我的结果集中返回,但还需要两列的总和在另一列中作为“DegreeDays”返回。我尝试了 SUM 函数,但无济于事,我尝试了一个简单的“HeatingDegreeDays + CoolingDegreeDays AS DegreeDays”,但也没有用。建议?
,CASE
WHEN TempLow > 60.5 THEN 0
WHEN ((TempHigh + TempLow)/2) > 60.5 THEN ((60.5-TempLow)/4)
WHEN TempHigh >= 60.5 THEN (((60.5 - TempLow)/2)-((TempHigh-TempLow)/4))
WHEN TempHigh < 60.5 THEN (60.5-(TempHigh+TempLow)/4)
END AS HeatingDegreeDays
,CASE
WHEN TempHigh < 66.25 THEN 0
WHEN ((TempHigh + TempLow)/2) < 66.25 THEN ((TempHigh-66.25)/4)
WHEN TempLow <= 66.25 THEN (((TempHigh - 66.25)/2)-((66.25-TempLow)/4))
WHEN TempLow > 66.25 THEN ((TempHigh+TempLow)/2)-66.25
END AS CoolingDegreeDays