我之前的问题没有得到一个好的答案。在这个问题中我提供了更多的东西,但仍然没有得到正确的结果..任何人都帮助我...
1st row amount=1200,
2nd row amount=1320(1200+120),
3rd row amount=1452(1320+132)
逻辑是按先前金额加10%
;WITH nums AS
(SELECT 1 AS RowNum, 1200 AS value
)
SELECT RowNum, Value
FROM nums
结果:
Sno - Name- Amount
1 - A - 1200
现在我想要这样的结果..
Sno - Name- Amount
1 - A - 1200
2 - A - 1320
3 - A - 1452
任何人都可以帮助我我在相同的查询中找不到任何逻辑,没有外部表创建或实现
答案 0 :(得分:0)
我来自Oracle背景;但我希望这有助于它在Oracle中适用于我:
WITH nums(rn, value) AS
(
SELECT ROWNUM rn, 1200 AS value FROM DUAL
UNION ALL
SELECT rn + 1 rn, round(value * 1.1) FROM nums
where rn < 100
)
SELECT RowNum, Value
FROM nums
最多可生成100行。
答案 1 :(得分:0)
你需要像这样使用Recursive CTE:
WITH nums(rn, value) AS
(
SELECT 1 rn, 1200 AS value
UNION ALL
SELECT rn + 1 rn, value + round(value/10,2) as value
FROM nums
where rn < 10
)
SELECT rn, Value
FROM nums
<强> SQL Fiddle Demo 强>