SELECT DATASET, BLOCKID, CATEGORY, TONNES * t100 AS True_Tonnes, VOLUME * t100 AS True_Volume, g100 AS Grade
FROM dbo.tblPTEvaluationRep_100ppm
我想计算True_Tonnes *等级并将其别名为AS' Metal'在我创建的同一个View表中。
答案 0 :(得分:0)
这样的东西?
SELECT DATASET,
BLOCKID,
CATEGORY,
TONNES * t100 AS True_Tonnes,
VOLUME * t100 AS True_Volume,
g100 AS Grade,
--
tonnes * t100 * g100 as Metal --> this
------------- ---- -----
True_Tonnes Grade Alias --> explanation
FROM dbo.tblPTEvaluationRep_100ppm
答案 1 :(得分:0)
您无法在SELECT
中重复使用别名。您有四种选择:
在SQL Server中,最后一种方法使用APPLY
:
SELECT p.DATASET, p.BLOCKID, p.CATEGORY,
v.True_Tonnes, v.True_Volume, v.Grade,
(v.True_Tonnes * v.Grade) as Metal
FROM dbo.tblPTEvaluationRep_100ppm p
(VALUES (p.TONNES * t100, p.VOLUME * p.t100, g100)
) v(True_Tonnes, True_Volume, Grade);
答案 2 :(得分:0)
您可以使用以下查询
选择 数据集 BLOCKID, 类别, TONNES * t100 AS True_Tonnes, VOLUME * t100 AS True_Volume, g100 AS等级,吨* t100 * g100为金属 来自dbo.tblPTEvaluationRep_100ppm