繁体   English   中英

Mysql 查询存储过程

[英]Mysql Query to Stored Procedure

我可以访问具有以下值的数据表(mysql 8)的视图:

价值观数据库

现在我尝试编写一个 mysql 查询来用最后一个值填充 Null 值,因为我们的可视化工具无法使用 null 值并且图中的线条会消失。

SELECT UTCTIME,
case when Flammtemperatur1 is NULL then
@vorheriger_wert_Flammtemperatur1
else
@vorheriger_wert_Flammtemperatur1 := Flammtemperatur1
end as Flammtemperatur_1,
case when Flammtemperatur2 is NULL then
@vorheriger_wert_Flammtemperatur2
else
@vorheriger_wert_Flammtemperatur2 := Flammtemperatur2
end as Flammtemperatur_2,
case when Rauchgasventilator is NULL then
@vorheriger_wert_Rauchgasventilator
else
@vorheriger_wert_Rauchgasventilator := Rauchgasventilator
end as Rauchgasventilator_,
case when Rezirkulation is NULL then
@vorheriger_wert_Rezirkulation
else
@vorheriger_wert_Rezirkulation := Rezirkulation
end as FRezirkulation_
FROM pivot_test
order by utctime asc

这很好用,但我需要将其保存在视图或存储过程中,以便我们的工具可以访问它。 由于 session 变量,无法查看。 有人可以帮我为我的问题创建一个存储过程吗? 我以前从未写过SP。

谢谢!

结果

CREATE PROCEDURE XXXXXName @Flammtemperatur1 DECIMAL (3,2), @Flammtemperatur2 DECIMAL (3,2), @Rauchgasventilator DECIMAL (3,2),@Rezirkulation DECIMAL (3,2) AS SELECT UTCTIME, case when Flammtemperatur1 is NULL then @vorheriger_wert_Flammtemperatur1 else @vorheriger_wert_Flammtemperatur1:= Flammtemperatur1 end as Flammtemperatur_1, case when Flammtemperatur2 is NULL then @vorheriger_wert_Flammtemperatur2 else @vorheriger_wert_Flammtemperatur2:= Flammtemperatur2 end as Flammtemperatur_2, case when Rauchgasventilator is NULL then @vorheriger_wert_Rauchgasventilator else @vorheriger_wert_Rauchgasventilator:= Rauchgasventilator end as Rauchgasventilator_, case when Rezirkulation is NULL 然后@vorheriger_wert_Rezirkulation else @vorheriger_wert_Rezirkulation:= Rezirkulation end as FRezirkulation_ FROM pivot_test order by utctime asc

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM