with t1 as
(
select 1 id, null c1, 18.97/100 c2 from dual
union all
select 2 id, 0.04/100 c1, null from dual
union all
select 3 id, 0.02/100 c1, null from dual
union all
select 4 id, 0.02/100 c1, null from dual
union all
select 5 id, -0.02/100 c1, null from dual
union all
select 6 id, 0.02/100 c1, null from dual
)
select id, c1, c2
, case when id=1 then c2 else (exp(sum(ln((1+nvl(c1, 0))*(1+nvl(c2,0)))) over(order by id)))-1 end
from t1
with t1 as
(
select 1 id, null c1, 18.97/100 c2 from dual
union all
select 2 id, 0.04/100 c1, null from dual
union all
select 3 id, 0.02/100 c1, null from dual
union all
select 4 id, 0.02/100 c1, null from dual
union all
select 5 id, -0.02/100 c1, null from dual
union all
select 6 id, 0.02/100 c1, null from dual
)
select id, c1, c2
, case when id=1 then c2 else (exp(sum(ln((1+nvl(c1, 0))*(1+nvl(c2,0)))) over(order by id)))-1 end
from t1
結果和我用EXCEL算出來有微小差異
我試了,如果小數點后位數夠多,結果是一樣的。
不一樣,我把小數位全帶進去算了截圖如下,
圖一為準確結果:
圖二為SQL計算結果
大神,幫忙再看看,這陳述句屬實有點看不明白,感謝!
uj5u.com熱心網友回復:
這樣?
with t1 as
(
select 1 id, null c1, 18.97/100 c2 from dual
union all
select 2 id, 0.04/100 c1, null from dual
union all
select 3 id, 0.02/100 c1, null from dual
union all
select 4 id, 0.02/100 c1, null from dual
union all
select 5 id, -0.02/100 c1, null from dual
union all
select 6 id, 0.02/100 c1, null from dual
)
select id, c1, c2
, case when id=1 then c2 else (exp(sum(ln((1+nvl(c1, 0))*(1+nvl(c2,0)))) over(order by id)))-1 end
from t1
結果和我用EXCEL算出來有微小差異
我試了,如果小數點后位數夠多,結果是一樣的。
不一樣,我把小數位全帶進去算了截圖如下,
圖一為準確結果:
圖二為SQL計算結果
大神,幫忙再看看,這陳述句屬實有點看不明白,感謝!
就拿第二行舉例子:
select (1+0.170495255)*(1-0.000999861061490215)-1 from dual
你看一下結果是多少,在計算器中也計算一下,看看結果是多少。
uj5u.com熱心網友回復:
再執行
with t1 as
(
select 1 id, null c1, 0.170495255 c2 from dual
union all
select 2 id, -0.000999861061490215 c1, null from dual
)
select id, c1, c2
, case when id=1 then c2 else (exp(sum(ln((1+nvl(c1, 0))*(1+nvl(c2,0)))) over(order by id)))-1 end
from t1
看看結果是多少。
**桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......
我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......
關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......