Skip to content

Commit 8be2be0

Browse files
authored
Update # 1587. Bank Account Summary II.sql
1 parent 5214243 commit 8be2be0

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

Customers or Users/# 1587. Bank Account Summary II.sql

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,11 @@ SELECT u.name AS NAME,SUM(t.amount) AS BALANCE
77
FROM Transactions t LEFT JOIN Users u
88
ON u.account = t.account
99
GROUP BY u.account
10+
# Aggregate function can go directly after HAVING
1011
HAVING SUM(t.amount)>10000;
1112

1213

13-
14-
15-
select u.name,
16-
tb1.amount_sum AS balance
17-
from Users u join
18-
(select account,
19-
SUM(amount) AS amount_sum
20-
from Transactions
21-
group by account) tb1
22-
on u.account = tb1.account
23-
where tb1.amount_sum > 10000
24-
25-
26-
27-
14+
# Second solution
2815
with tmp as(
2916
select t.account, u.name, sum(amount) as balance
3017
from Transactions t
@@ -33,4 +20,4 @@ group by account )
3320

3421
select name, balance
3522
from tmp
36-
where balance > 10000
23+
where balance > 10000

0 commit comments

Comments
 (0)