简体   繁体   English

Mysql 查询存储过程

[英]Mysql Query to Stored Procedure

i have got access to a view of a datatable (mysql 8) which has the following values:我可以访问具有以下值的数据表(mysql 8)的视图:

Values DB价值观数据库

now I tried to write an mysql query to fill up the Null values with the last value, because our visualisation tool cannot use null values and the lines in the graph will disappear.现在我尝试编写一个 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

That works fine, but i need to save this in a view or stored procedure, so that our tool can have access to it.这很好用,但我需要将其保存在视图或存储过程中,以便我们的工具可以访问它。 Views are not possible because of the session variables.由于 session 变量,无法查看。 Can someone please help me creating a Stored procedure for my problem?有人可以帮我为我的问题创建一个存储过程吗? I have never written a SP before.我以前从未写过SP。

Thanks!谢谢!

Result结果

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 then @vorheriger_wert_Rezirkulation else @vorheriger_wert_Rezirkulation:= Rezirkulation end as FRezirkulation_ FROM pivot_test order by utctime asc 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