Snoopy [리트코드/SQL] 32. Bank Account Summary II (1587)
코딩테스트/리트코드 SQL

[리트코드/SQL] 32. Bank Account Summary II (1587)

Sooyoon Jeong 2023. 2. 14.
 

Bank Account Summary II - LeetCode

Bank Account Summary II - Table: Users +--------------+---------+ | Column Name | Type | +--------------+---------+ | account | int | | name | varchar | +--------------+---------+ account is the primary key for this table. Each row of this table contains t

leetcode.com


🤔 문제 분석

1) Write an SQL query to report the name and balance of users with a balance higher than 10000. The balance of an account is equal to the sum of the amounts of all transactions involving that account.

 

💡 풀이

SELECT name, balance
FROM (SELECT T.account, U.name, SUM(amount) AS balance
      FROM Transactions AS T
      JOIN Users AS U ON T.account = U.account
      GROUP BY T.account, U.name) AS sub
WHERE balance > 10000

 

 

댓글