我想要达到的结果
电表每小时记录一次当前数值加到表中,算出每个电表每小时、每天、每周的用电量,每层电表每小时、每天、每周用电量
电表每小时记录一次当前数值加到表中,算出每个电表每小时、每天、每周的用电量,每层电表每小时、每天、每周用电量
把你最后要展现的数据格式列出来一下,看看是要几张结果表,分别有哪些字段
给你一个这样的sql应该就够了,其他的都是基于这个数据去做汇总
SELECT
pointrecordid,
DATEPART(year, pointrecorddatetime) 年份,
DATEPART(month, pointrecorddatetime) 月份,
CONVERT(varchar(100), pointrecorddatetime, 111) 日期,
concat(CONVERT(varchar(100), lag ( pointrecorddatetime ) OVER ( partition BY pointrecordid ORDER BY pointrecorddatetime ), 21) ,'~',CONVERT(varchar(100), pointrecorddatetime, 21) ) 时段,
pointrecordvalue - lag ( pointrecordvalue ) OVER ( partition BY pointrecordid ORDER BY pointrecorddatetime ) 用电量,
flooridfk
FROM
test_20211228