天天看點

開窗函數OVER(PARTITION BY... ORDER BY...)詳解

本文轉自:【Orcale】分析函數 OVER(PARTITION BY... ORDER BY...)的講解

項目中用到分組排序,求和之類的,這位小哥寫的很詳細,記錄一下

算當期之後剩餘的本金利息和

select rid||'',lid,indexs,should_capital,fact_capital,should_interest,fact_interest,
sum(should_capital) over(partition by lid order by indexs desc) - should_capital as rest_capital,
sum(should_interest) over(partition by lid order by indexs desc) - should_interest as rest_interest
 from ods.s02_loan_repayment; 
           
開窗函數OVER(PARTITION BY... ORDER BY...)詳解