USE Saleslogix
DECLARE @AssumedGrowth int
SET @AssumedGrowth = 28
SELECT
account,
employees as NumberIn2013,
@AssumedGrowth += employees as NumberIn2014
FROM sysdba.account
WHERE employees <> 'NULL'
and account like 'Shaw%'它告诉我+=是无效的,只能与+一起使用。有没有人能帮我把这个例子变成一个复合运算符?我不知道这是否有太大的不同,但我使用的是2005 Management Studio。
另外,如果这不是一个巨大的痛苦,添加同样的例子,@AssumedGrowth是一个百分比?
发布于 2014-05-22 19:59:53
您想要做的是:
SELECT account, employees as NumberIn2013,
(@AssumedGrowth = @AssumedGroup + employees) as NumberIn2014
FROM sysdba.account
WHERE employees <> 'NULL' and account like 'Shaw%';但是,我认为这是行不通的。相反,我建议使用内置功能,特别是row_number()
SELECT account, employees as NumberIn2013,
employees * pow(1 + @AssumedGrowth/100.0, row_number() over (order by <field>) - 1)
FROM sysdba.account
WHERE employees <> 'NULL' and account like 'Shaw%';请注意,您需要指定结果的排序。假设有某种id或datetime列具有适当的顺序。表表示无序集合,因此没有“第一”行。
https://stackoverflow.com/questions/23806104
复制相似问题