开窗函数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...)详解_第1张图片

你可能感兴趣的:(#,Hive,数据库,#,Oracle)