我希望能够在查询中创建临时变量 - 而不是存储过程或函数 - 不需要声明和设置,以便我不需要通过我称之为查询参数。在查询中创建临时变量
试图向这方面努力:
Select field1,
tempvariable=2+2,
newlycreatedfield=tempvariable*existingfield
From
table
从这个
离开:
DECLARE @tempvariable
SET @tempvariable = 2+2
Select field1,
[email protected]*existingfield
From
table
谢谢您的时间
我可能过于复杂的例子;更简单地说,以下给出无效列名QID
Select
QID = 1+1
THN = QID + 1
如果这是在一个查询中,是否有解决方法?子查询
Select field1, tempvariable,
(tempvariable*existingfield) as newlycreatedfield
from (select t.*, (2+2) as tempvariable
from table t
) t;
不幸的是,MySQL有实际实例化的倾向(即创建)派生表:
有你不想使用存储过程的原因? – acutesoftware
如果我已经完成了,我可能会这样做,但是这几行代码会包含数以千计的其他计算数据,并且这些数据会在更大的查询中出现。谢谢 – user2723494