最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

database_leetcode 2066. Account Balance

2022-02-13 16:51 作者:您是打尖兒還是住店呢  | 我要投稿

Table: Transactions


+-------------+------+

| Column Name | Type |

+-------------+------+

| account_id? | int? |

| day? ? ? ? ?| date |

| type? ? ? ? | ENUM |

| amount? ? ? | int? |

+-------------+------+

(account_id, day) is the primary key for this table.

Each row contains information about one transaction, including the transaction type, the day it occurred on, and the amount.

type is an ENUM of the type ('Deposit','Withdraw')?



Write an SQL query to report the balance of each user after each transaction. You may assume that the balance of each account before any transaction is 0 and that the balance will never be below 0 at any moment.


Return the result table in ascending order by account_id, then by day in case of a tie.


The query result format is in the following example.




Example 1:


Input:?

Transactions table:

+------------+------------+----------+--------+

| account_id | day? ? ? ? | type? ? ?| amount |

+------------+------------+----------+--------+

| 1? ? ? ? ? | 2021-11-07 | Deposit? | 2000? ?|

| 1? ? ? ? ? | 2021-11-09 | Withdraw | 1000? ?|

| 1? ? ? ? ? | 2021-11-11 | Deposit? | 3000? ?|

| 2? ? ? ? ? | 2021-12-07 | Deposit? | 7000? ?|

| 2? ? ? ? ? | 2021-12-12 | Withdraw | 7000? ?|

+------------+------------+----------+--------+

Output:?

+------------+------------+---------+

| account_id | day? ? ? ? | balance |

+------------+------------+---------+

| 1? ? ? ? ? | 2021-11-07 | 2000? ? |

| 1? ? ? ? ? | 2021-11-09 | 1000? ? |

| 1? ? ? ? ? | 2021-11-11 | 4000? ? |

| 2? ? ? ? ? | 2021-12-07 | 7000? ? |

| 2? ? ? ? ? | 2021-12-12 | 0? ? ? ?|

+------------+------------+---------+

Explanation:?

Account 1:

- Initial balance is 0.

- 2021-11-07 --> deposit 2000. Balance is 0 + 2000 = 2000.

- 2021-11-09 --> withdraw 1000. Balance is 2000 - 1000 = 1000.

- 2021-11-11 --> deposit 3000. Balance is 1000 + 3000 = 4000.

Account 2:

- Initial balance is 0.

- 2021-12-07 --> deposit 7000. Balance is 0 + 7000 = 7000.

- 2021-12-12 --> withdraw 7000. Balance is 7000 - 7000 = 0.

窗口函數(shù)處理即可

database_leetcode 2066. Account Balance的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
油尖旺区| 镇坪县| 平湖市| 微山县| 余干县| 渭南市| 安宁市| 儋州市| 江津市| 阳谷县| 武义县| 洪湖市| 峡江县| 兴文县| 织金县| 通城县| 淮南市| 济宁市| 金堂县| 云霄县| 靖西县| 伊春市| 和龙市| 宜兴市| 泗水县| 新邵县| 偏关县| 固阳县| 永年县| 博湖县| 亚东县| 青浦区| 闻喜县| 荃湾区| 彩票| 和硕县| 馆陶县| 开鲁县| 丹阳市| 专栏| 田阳县|