SQL MOSAIC #1587. Bank Account Summary II
Jul 5, 2022
Date:7/2/2022

Thinking Pathway:
- I added this question to my blog just to remind myself that there are two approaches.
- Use Having with a GROUP BY, or use a subquery.
Solution(s):
Solution1:
SELECT name, balance
FROM
(SELECT name, SUM(amount) AS balance
FROM Users u JOIN Transactions t ON u.account = t.account
GROUP BY t.account) AS T
WHERE balance >= 10000
Solution2:
SELECT name, SUM(amount) AS balance
FROM Users u JOIN Transactions t ON u.account = t.account
GROUP BY t.account
HAVING balance >= 10000