我想使用以下语法来创建 MySQL View :
create view `ViewName` as (select
v_starting.callingname,
v_starting.geofence,
v_starting.`updatetime`,
@lastGroup := @lastGroup + if( @lastAddress = v_starting.geofence
AND @lastVehicle = v_starting.callingname, 0, 1 ) as GroupSeq,
@lastVehicle := v_starting.callingname as justVarVehicleChange,
@lastAddress := v_starting.geofence as justVarAddressChange
from
v_starting,
( select @lastVehicle := '',
@lastAddress := '',
@lastGroup := 0 ) SQLVars
order by
v_starting.`updatetime` )
此操作失败并出现错误:
#1351 - View's SELECT contains a variable or parameter
我该如何解决这个问题?谢谢一百万。
最佳答案
如 CREATE VIEW
Syntax 下所述:
A view definition is subject to the following restrictions:
[ <strong><em>deletia</em></strong> ]
- The
SELECT
statement cannot refer to system or user variables.
关于mysql 使用包含变量的 mysql 查询创建 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16278705/