嗨,这是我在mysql中使用的代码,它的工作正常。有没有办法为GRP声明一个变量并在代码中调用它。所以我可以再次使用代码,如果我必须在grp和任何其他名称之外的其他列上进行数学运算,因为名称一直在变化
SELECT GRP,
@_11:=power(GRP,0.1)+0.1*@_11 AS GRP_11 ,
@_12:=power(GRP,0.2)+0.1*@_12 AS GRP_12 ,
@_13:=power(GRP,0.3)+0.1*@_13 AS GRP_13 ,
@_14:=power(GRP,0.4)+0.1*@_14 AS GRP_14 ,
@_15:=power(GRP,0.5)+0.1*@_15 AS GRP_15 ,
@_16:=power(GRP,0.6)+0.1*@_16 AS GRP_16 ,
@_17:=power(GRP,0.7)+0.1*@_17 AS San_Orange_CS_GRP_17 ,
@_18:=power(GRP,0.8)+0.1*@_18 AS GRP_18 ,
@_19:=power(GRP,0.9)+0.1*@_19 AS GRP_19 ,
from DUMMY JOIN (SELECT @_11:=0,@_12:=0,@_13:=0,@_14:=0,@_15:=0,@_16:=0,
@_17:=0,@_18:=0,@_19:=0) t;
提前致谢...
答案 0 :(得分:0)
您可以使用内联变量。
示例:
select @grp:=GRP as grp, @_11:=power( @grp,0.1)+0.1*@_11 AS GRP_11, ...
更改您的查询,如下所示:
SELECT
@grp := GRP as grp,
@_11 := power( @grp, 0.1 ) + 0.1 * @_11 AS GRP_11 ,
@_12 := power( @grp, 0.2 ) + 0.1 * @_12 AS GRP_12 ,
@_13 := power( @grp, 0.3 ) + 0.1 * @_13 AS GRP_13 ,
@_14 := power( @grp, 0.4 ) + 0.1 * @_14 AS GRP_14 ,
@_15 := power( @grp, 0.5 ) + 0.1 * @_15 AS GRP_15 ,
@_16 := power( @grp, 0.6 ) + 0.1 * @_16 AS GRP_16 ,
@_17 := power( @grp, 0.7 ) + 0.1 * @_17 AS San_Orange_CS_GRP_17 ,
@_18 := power( @grp, 0.8 ) + 0.1 * @_18 AS GRP_18 ,
@_19 := power( @grp, 0.9 ) + 0.1 * @_19 AS GRP_19 ,
FROM DUMMY
JOIN (
SELECT @_11:=0, @_12:=0, @_13:=0, @_14:=0, @_15:=0,
@_16:=0, @_17:=0, @_18:=0, @_19:=0
) t;