错误:视图的SELECT包含变量或参数

时间:2019-03-28 20:11:08

标签: mysql sql

我正在使用MySQL工作台8:

由于出现以下错误,我无法创建此视图: View的SELECT包含变量或参数

这是我的观点:

Create view history as
select ShippedDate, round(previous_operation) as DayEnd, DayStart ,Reorderunits,Quantity,reorderlevel from (
select
y.*
, @prev AS previous_Operation
, @prev := DayStart
from
ExpectedHistory y
, (select @prev:=NULL) vars
order by ShippedDate desc

注意:@prev保存一个整数值

1 个答案:

答案 0 :(得分:0)

如果要在MySQL 8+中进行先前的操作,请使用lead()

create view history as
    select ShippedDate, DayStart,
           lead(day_start) over (partition by shippeddate) as as dayend,
           Reorderunits, Quantity, reorderlevel,
    from ExpectedHistory eh;