我需要按特定数字在select语句中递增。我理解这一点: -
SELECT ROW_NUMBER() OVER( ORDER BY SomeColumn ) AS 'rownumber',*
FROM YourTable
但是我需要像下面的陈述。但是来自c#,我只是想从tsql中展示我需要的东西: -
SELECT
xValue,
@x = @x + 0.009 as yValue
FROM
Table
WHERE
ID = 1
假设此语句返回10行。请帮忙。
答案 0 :(得分:1)
你在找这样的东西吗?
SELECT TOP 10 name
,CAST(ROW_NUMBER() OVER(ORDER BY name) AS decimal(16,3)) * 0.009
FROM sys.objects
使用中的因素(这里是0.009)可以很容易地作为变量传递......
如果您想以0
SELECT TOP 10 name
,CAST((ROW_NUMBER() OVER(ORDER BY name)-1) AS decimal(16,3)) * 0.009
FROM sys.objects
答案 1 :(得分:0)
您不希望将每个ROW_NUMBER()乘以增量值吗?
SELECT TOP 10
AccountNumber,
ROW_NUMBER() OVER(ORDER BY AccountNumber) * 10 AS 'yValue'
FROM dbo.Acccounts
AccountNumber yValue
1 10
2 20
3 30
4 40
5 50
6 60
30106 70
30107 80
30108 90
30109 100