看板 Database 關於我們 聯絡資訊
你好,我有想到用procedure 的方法 首先 我在你的表格建立PK id 方便後續操作 語法如下: create or replace procedure pro01 is i number; j number; begin select max(id) into i from yourtable; select min(id) into j from yourtable; LOOP exit when i<j; update yourtable set results=(select sum(value) from yourtable where id<i) where id=i; i:=i-1; END LOOP; 建立procedure後 每當你有更新value 就執行 execute pro01; 就會幫你更新 但如果你想要完全自動更新,可能就要搭配trigger+procedure了(有嘗試這樣做, 但一直失敗) 小弟淺見 end;※ 引述《lunenknight (BlackMilk)》之銘言: : 內容/問題描述:SQL語法問題 : 假設我有一個資料表如下 : Date Value "Results" : 05/01/01 300 300 : 05/01/02 200 500 : 05/01/03 -100 400 : 05/01/04 -200 200 : 05/01/05 500 700 : . . . : . . . : . . . : 我要如何取results值 永遠是自己日期以前的value相加 : 因為需要可以從中間直接更新value值 例如: 將05/01/03 的value更新為 -200 : 之後的results值 要依序更新為 300 100 600 : 請問要如何下手... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 124.199.97.84 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1423789745.A.43A.html
sonesnsdsosi: 因為看到你的日期都是遞增的 所以想到用max min方法 02/13 09:55