plsql逐行累加
plsql逐行累加
Select eba002,buydate,
2 buynum,outnum,nvl(Sum(buynum) over (partition by eba002 order by buydate),0)sumbuy,nvl(Sum(outnum)over (partition by eba002 order by buydate),0) sunout
3 From zhugyt1
plsql逐行累加
EBA002 BUYDATE BUYNUM OUTNUM
---------- ---------- ---------- -----------------
91001 2008-1-1 200
91001 2008-1-2 300 50
91001 2008-1-3 100
91002 2008-1-1 100
91002 2008-1-2 20
91002 2008-1-3 50
需要依據eba002計算出總的購入數與銷出數,結果如下:
EBA002 BUYDATE BUYNUM OUTNUM SUMBUY SUNOUT
---------- ---------- ---------- ----------------- ---------- ----------
91001 2008-1-1 200 200 0
91001 2008-1-2 300 50 500 50
91001 2008-1-3 100 500 150
91002 2008-1-1 100 100 0
91002 2008-1-2 20 120 0
91002 2008-1-3 50 120 50
一下子感覺竟是似曾相識,卻想不起來,原來可以用
Select eba002,buydate,
2 buynum,outnum,nvl(Sum(buynum) over (partition by eba002 order by buydate),0)sumbuy,nvl(Sum(outnum)over (partition by eba002 order by buydate),0) sunout
3 From zhugyt1
解決.
對sum() over(partition by...)看來還得多熟悉.不知sqlserver類似問題又是如何解決的.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11419868/viewspace-1008033/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle plsqlOracleSQL
- 逐行解析Axios原始碼iOS原始碼
- 滿足條件的數累加被17整除的數的累加
- PLSQL Developer 14SQLDeveloper
- plsql use skillsSQL
- plsql配置使用SQL
- DreamJudge-1446-日期累加
- 1206 簡單的累加
- PLSQL程式語言SQL
- PLSQL Developer 行號SQLDeveloper
- plsql中文亂碼SQL
- windows安裝plsqlWindowsSQL
- PLSQL Developer配置使用SQLDeveloper
- 0710_plsql 函式SQL函式
- 牛客 KY258 : 日期累加
- 用閉包做累加器
- 逐行閱讀redux原始碼(一) createStoreRedux原始碼
- 逐行閱讀redux原始碼(二)combineReducersRedux原始碼
- 逐行分析Koa中介軟體機制
- [20180511]PLSQL與fetchsize.txtSQL
- PLSQL Developer 12 註冊碼SQLDeveloper
- plsql 除錯 pipelined 函式SQL除錯函式
- plsql developer 視窗的使用SQLDeveloper
- canvas 旋轉角度不需要累加Canvas
- 陣列累加和問題三連陣列
- [20240807]數值累加的問題.txt
- golang 效能優化之累加雜湊Golang優化
- Java HashMap 原始碼逐行解析(JDK1.8)JavaHashMap原始碼JDK
- 逐行分析鴻蒙系統的 JavaScript 框架鴻蒙JavaScript框架
- [20191021]數值累加的各種方法.txt
- 6. PLSQL 編寫規範SQL
- 配置PLSQL Developer詳細步驟SQLDeveloper
- PLSQL只匯出表結構SQL
- plsql developer 15的安裝配置SQLDeveloper
- plsql developer工具生成sql monitor reportSQLDeveloper
- Oracle vs PostgreSQL Develop(29) - COMMIT in PLSQLOracleSQLdevMIT
- 逐行閱讀redux原始碼(三)bindActionCreators & applyMiddleware & composeRedux原始碼APP
- 逐行分析Koa v1 中介軟體原理
- Shell指令碼逐行處理文字檔案技巧指令碼