Bank Account Summary II — LeetCode 1587 Python Solution
EasyDatabase
- Problem
- #1587
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
SQL
Table: Users +--------------+---------+ | Column Name | Type | +--------------+---------+ | account | int | | name | varchar | +--------------+---------+ account is the primary key (column with unique values) for this table. Each row of this table contains the account number of each user in the bank.Example
SQL
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| account | int |
| name | varchar |
+--------------+---------+
account is the primary key (column with unique values) for this table.
Each row of this table contains the account number of each user in the bank.
There will be no two users having the same name in the table.Python solution
Python
import duckdb
import pandas as pd
def solution(users: pd.DataFrame, transactions: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Users", users)
con.register("Transactions", transactions)
return con.execute("""SELECT
name,
SUM(amount) AS balance
FROM
Users
JOIN Transactions USING (account)
GROUP BY account
HAVING balance > 10000;""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 1587. Bank Account Summary II?
- LeetCode 1587. Bank Account Summary II is rated Easy on LeetCode.
- What topics does LeetCode 1587. Bank Account Summary II cover?
- LeetCode 1587. Bank Account Summary II is tagged Database on LeetCode.