久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何將 1 條記錄數據添加到以前的數據?

How to add 1 records data to previous?(如何將 1 條記錄數據添加到以前的數據?)
本文介紹了如何將 1 條記錄數據添加到以前的數據?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我遇到了問題,比如我正在傳遞 accountID 并根據該 SP 選擇一個人的金額詳細信息,例如

i am stuck in problem like i am passing accountID and on the basis of that SP picks amount details of a person e.g.

AccountID   AccountTitle  TransactionDate Amount

1           John01        2014/11/28      20

現在,如果同一個 accountID 有第二個或更多記錄,那么它應該添加以前的 e.g.如果 accountID 1 的第二條記錄是 40,則金額應顯示 60(這樣它應該已經添加到 20 并在第二條記錄中顯示總數)

now if there is 2nd or more records for same accountID then it should add with previous e.g. if 2nd record for accountID 1 is 40 then amount should display 60 (such that it should be already added to 20 and display total in 2nd record)

AccountID   AccountTitle  TransactionDate Amount

    1           John01        2014/12/30    60    (in real it was 40 but it should show result after being added to 1st record)

同樣適用于更多的記錄

Select Payments.Accounts.AccountID, Payments.Accounts.AccountTitle, 
       Payments.Transactions.DateTime as TranasactionDateTime, 
       Payments.Transactions.Amount from Payments.Accounts
       Inner Join Payments.Accounts
       ON Payments.Accounts.AccountID = Payments.Transactions.Account_ID
       Inner Join Payments.Transactions
       where Payments.Transactions.Account_ID = 1

它浪費了我的時間,無法再解決它,所以請幫助我,

it has wasted my time and can't tackle it anymore, so please help me,

推薦答案

SQL Server 2012+ 支持累積總和(這似乎是你想要的):

SQL Server 2012+ supports cumulative sums (which seems to be what you want):

Select a.AccountID, a.AccountTitle, t.DateTime as TranasactionDateTime, 
       t.Amount,
       sum(t.Amount) over (partition by t.Account_Id order by t.DateTime) as RunningAmount    
from Payments.Accounts a Inner Join
     Payments.Transactions t
     on a.AccountID = t.Account_ID
where t.Account_ID = 1;

在早期版本的 SQL Server 中,您可以使用相關子查詢或使用 cross apply 最輕松地做到這一點.

In earlier versions of SQL Server you can most easily do this with a correlated subquery or using cross apply.

我還修復了您的查詢.我不知道你為什么兩次加入 Accounts 表.此外,表別名使查詢更易于編寫和閱讀.

I also fixed your query. I don't know why you were joining to the Accounts table twice. Also, table aliases make queries much easier to write and to read.

這篇關于如何將 1 條記錄數據添加到以前的數據?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日韩乱码在线 | 国产日韩欧美激情 | 毛片免费观看 | 亚洲一区二区中文字幕 | 亚洲一区二区免费 | 欧美激情视频一区二区三区在线播放 | 视频一区二区在线观看 | 在线一区视频 | 久久久久久国产精品久久 | 国产美女一区二区 | 成人精品国产 | 午夜视频一区二区 | 久久久www成人免费无遮挡大片 | 久久久久亚洲精品 | 成人自拍视频网站 | 国产精品性做久久久久久 | 欧美亚洲激情 | 久久久99国产精品免费 | 久久国产视频播放 | 一区二区免费视频 | 日韩视频在线一区 | 综合久久99| 国产欧美精品在线 | 欧美久 | 91久久久久久久久 | 久久成人免费视频 | 亚洲九九精品 | 国产欧美在线 | 国内精品久久精品 | 亚卅毛片| 成人av一区 | 免费久久网站 | av网站免费看 | 91国在线高清视频 | 一本在线 | 蜜桃一区二区三区 | 国内自拍偷拍一区 | 日韩三级一区 | 欧美国产精品一区二区三区 | 久久久天堂 | av在线免费不卡 |