From 3e3cc0087a5e359898ffea50d00874daf112ac98 Mon Sep 17 00:00:00 2001 From: zch Date: Mon, 25 Nov 2024 17:05:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E8=92=B8=E6=B1=BD=E6=95=B0=E6=8D=AE=E7=9A=84=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建了一个名为 Record_SteamPointData 的存储过程- 该过程用于记录蒸汽流量数据,计算消耗量,并插入到报告表中 - 主要功能包括: - 获取最近一小时的蒸汽流量数据 -计算蒸汽消耗量 - 将数据插入到 ems_report_point_steam 表中 --- 选择的那个sql.sql | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 选择的那个sql.sql diff --git a/选择的那个sql.sql b/选择的那个sql.sql new file mode 100644 index 0000000..14042d6 --- /dev/null +++ b/选择的那个sql.sql @@ -0,0 +1,40 @@ +CREATE PROCEDURE [dbo].[Record_SteamPointData] +AS +BEGIN + declare @begin_time datetime + declare @end_time datetime + declare @dateinfo datetime; + + set @begin_time = DATEADD(hh, -1, GETDATE()); + set @end_time = DATEADD(hh, -0, GETDATE()); + set @dateinfo = GETDATE(); + + WITH LatestSteam AS ( + SELECT + T1.monitor_code, + T1.steam_flow, + ROW_NUMBER() OVER (PARTITION BY T1.monitor_code ORDER BY T1.collect_time DESC) AS rn + FROM ems_record_steam_instant T1 + WHERE T1.collect_time BETWEEN DATEADD(HH, -1, @dateinfo) AND DATEADD(HH, 0, @dateinfo) + ), + LatestReport AS ( + SELECT + E1.monitor_code, + E1.begin_time, + E1.instrument_value, + ROW_NUMBER() OVER (PARTITION BY E1.monitor_code ORDER BY E1.begin_time DESC) AS rn + FROM ems_report_point_steam E1 + ) + INSERT INTO ems_report_point_steam (monitor_code, expend, instrument_value, begin_time, end_time, record_time) + SELECT + t1.monitor_code AS monitor_code, + CONVERT(DECIMAL(18, 2), ISNULL((t3.steam_flow - t4.instrument_value), 0)) AS expend, + ISNULL(t3.steam_flow, 0) AS instrument_value, + DATEADD(HH, -1, @dateinfo) AS begin_time, + DATEADD(HH, 0, @dateinfo) AS end_time, + CONVERT(VARCHAR(30), DATEADD(HH, -1, @dateinfo), 120) AS record_time + FROM ems_base_monitor_info t1 + LEFT JOIN LatestSteam t3 ON t1.monitor_code = t3.monitor_code AND t3.rn = 1 + LEFT JOIN LatestReport t4 ON t1.monitor_code = t4.monitor_code AND t4.rn = 1; +END; +GO \ No newline at end of file