分享至
各位先進好小弟目前有一個新表,希望新增一個欄位’當日發電時數’,定義為"今日總發電時數-昨日總發電時數"
已邀請的邦友 {{ invite_list.length }}/5
SELECT a1 AS 'Date',a2 AS 'Time',a3 AS '總發電量kWh',a4 AS '總發電時數', a5 as '當日發電量',ROUND(a4-lag(a4, 1, a4) OVER (ORDER BY a1),2) AS '當日發電時數' FROM aa ORDER BY a1, a2
Demo
太強大了,馬上解決我的問題了 感恩
Select *,ROUND(TolGeneratedTime-lag(TolGeneratedTime,1,TolGeneratedTime) OVER (ORDER BY [Date]),2) AS '當日發電時數' FROM tb_SolarStation_Daily
IT邦幫忙