0
我有一個表與多個僱員的工資。 我需要使用派生數(平均值和stddev)爲這些員工計算分數,並將其作爲新列添加。SQL Server變量如何工作?
我知道我可以在select語句中做到這一點,但如果我想看看我是否可以使用變量。
因此可以動態進行更改。我是SQL新手,只是試圖在這裏學習東西。
declare @Weight int,
@weight2 int,
@Mean int,
@StdDevn int,
@Variance int
set @Weight = 30
set @weight2 = (POWER(@weight,2)/100)
SELECT @Mean = AVG(salary) FROM [live].[dbo].[salary]
SELECT @StdDevn = STDEV(salary) FROM [live].[dbo].[salary]
SELECT @Variance = (POWER(@StdDevn,2)/100)
-- I should include some code here so that the above variable are passed to below query
SELECT * FROM [live].[dbo].[salary], (([salary][email protected])/@StdDevn)
錯誤:
Must declare variable @Mean, Incorrect syntax near '-'.