[LeetCode] Bank Account Summary II

아르당·2026년 5월 31일

LeetCode

목록 보기
333/579
post-thumbnail

문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음

Problem

Table: Users

Column NameType
accountint
namevarchar

account는 이 테이블의 고유 키이다.
각 행은 은행의 각 유저의 account number를 포함한다.
테이블에 똑같은 이름을 가진 사람은 없다.

Table: Transactions

Column NameType
trans_idint
accountint
amountint
transacted_ondate

trans_id는 이 테이블의 고유 키이다.
이 테이블의 각 행은 모든 계좌의 모든 변경사항을 포함한다.
사용자가 돈을 받으면 금액은 양수이고, 송금하면 금액은 음수이다.
모든 계좌의 잔액은 0부터 시작한다.

계좌 잔액이 10,000을 초과하는 사용자의 이름과 잔액을 보고하는 방법을 작성해라. 계좌 잔액은 해당 계좌와 관련된 모든 거래 금액의 합계이다.

Example

Input:
Users table:

accountname
900001Alice
900002Bob
900003Charlie

Transactions table:

trans_idaccountamounttransacted_on
190000170002020-08-01
290000170002020-09-01
3900001-30002020-09-02
490000210002020-09-12
590000360002020-08-07
690000360002020-09-07
7900003-40002020-09-11

Output:

namebalance
Alice11000

Solved

-- Write your PostgreSQL query statement below
select A.name, sum(B.amount) as balance
from Users as A
join Transactions as B on A.account = B.account
group by A.account, A.name
having sum(B.amount) > 10000;
profile
내 마음대로 코드 작성하는 세상

0개의 댓글