Skip to content

Latest commit

 

History

History
47 lines (30 loc) · 1.28 KB

File metadata and controls

47 lines (30 loc) · 1.28 KB

English Version

题目描述

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 and the amount.
type is 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 you may assume that the balance will not be below 0 at any moment.

Return the result table ordered by account_id and day in ascending order.

The query result format is in the following example.

解法

SQL