SQL MOSAIC #1587. Bank Account Summary II

Summer Nie
Jul 5, 2022

Date:7/2/2022

Thinking Pathway:

  1. I added this question to my blog just to remind myself that there are two approaches.
  2. 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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response