本文介紹了如何創建一個 MySql 查詢來顯示多個客戶有個人余額的貸方和借方的運行余額的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有一張表,結構如下:在此處輸入圖片描述
I have a table as with the structure below: enter image description here
該表是針對不同客戶的簡單貸記表和借記表(每個客戶都有自己的 ID).
The Table is a simple credit and debit table for different customers ( each customer has his own ID).
交易發生在不同的日期.每筆交易都有自己的 ID,按時間順序生成.
Transactions take place on different dates. Each transaction has its own ID which is chronologically generated.
必須創建一個視圖來顯示每個客戶的運行余額.視圖給出了按時間順序排列的列表.
A view must be created as showing the running balance of each customer. The view gives the list chronologically arranged.
列表項是
- 交易:
- 身份證
- Customer_ID
- 日期
- 信用
- 借記和
- 余額(計算)
我想獲取解決上述問題的查詢代碼.感謝您的期待.
I would like to get the query code for solving the above problem. Thanking you in anticipation.
推薦答案
這應該可行
select transaction_id, customer_id, date, credit, debit,
abs(sum(ifnull(credit,0)) over (partition by customer_id order by date,credit,transaction_id ) - sum(ifnull(debit,0)) over(partition by customer_id order by date,debit,transaction_id)) as balance
from ledger
order by transaction_id;
這篇關于如何創建一個 MySql 查詢來顯示多個客戶有個人余額的貸方和借方的運行余額的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!