浮点值的开始日期= 00:00:00和结束日期HH:mm:ss之间的小时差

时间:2019-04-19 09:53:31

标签: sql sql-server

我需要计算用电量,它的计算方法是每小时平均用电量乘以每天工作的小时数。我可以将两个日期时间之间的小时datediff值相乘,开始日期时间始终为00,而结束日期为系统日期时间。我尝试了这段代码,但并没有帮助我。

SELECT @APower24Cell = AVG((CAST(ACurrent24Cell as FLOAT)*CAST(AVoltage3Sec as FLOAT))/10)/1000 ,
@BPower24Cell =  AVG((CAST(BCurrent24Cell as FLOAT)*CAST(BVoltage3Sec as FLOAT))/10)/1000 ,
@CPower24Cell =  AVG((CAST(CCurrent24Cell as FLOAT)*CAST(CVoltage3Sec as FLOAT))/10)/1000 ,
@APower35Cell =  AVG((CAST(ACurrent35Cell as FLOAT)*CAST(AVoltage3Sec as FLOAT))/10)/1000 ,
@BPower35Cell =  AVG((CAST(BCurrent35Cell as FLOAT)*CAST(BVoltage3Sec as FLOAT))/10)/1000 ,
@CPower35Cell =  AVG((CAST(CCurrent35Cell as FLOAT)*CAST(CVoltage3Sec as FLOAT))/10)/1000 
FROM Energomonitoring 
WHERE TS >= DATEADD(HOUR,-24,GETDATE()) GROUP BY TS

SET @FULLPOWER = (@APower24Cell+@BPower24Cell+@CPower24Cell+@APower35Cell+@BPower35Cell+@CPower35Cell) * DATEDIFF(hour, dateadd(hour, datepart(hour,GETDATE()),CAST(convert(varchar(20),getdate(),112) as datetime)), GETDATE())

0 个答案:

没有答案