在MySQL中,如果您想报告一个公式并在另一个公式中使用该结果,可以执行类似于以下操作:
SELECT @var1 := column1+column2 AS var1
, POWER(@var1,2) AS var2squared
FROM database.table;
在MS SQL Server中有相应的功能吗?
在MySQL中,如果您想报告一个公式并在另一个公式中使用该结果,可以执行类似于以下操作:
SELECT @var1 := column1+column2 AS var1
, POWER(@var1,2) AS var2squared
FROM database.table;
WITH data AS (
SELECT column1 + column2 AS var1
FROM table
)
SELECT var1, POWER(var1, 2) AS var2squared
FROM data;
SELECT v.Var1, POWER(v.Var1, 2) AS Var2Squared
FROM [Table] t
CROSS APPLY (SELECT t.Column1 + t.Column2 AS Var1) v
;
@var1
存在。