Skip to content

Commit 8da4e46

Browse files
committed
finish Monthly Transactions I
1 parent ac8cada commit 8da4e46

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

SQL/Monthly_Transactions_I.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Problem : https://leetcode.com/problems/monthly-transactions-i/description/?envType=study-plan-v2&envId=top-sql-50
2+
3+
SELECT TO_CHAR(trans_date, 'YYYY-MM') as month,
4+
country, count(*) as trans_count,
5+
SUM(
6+
CASE
7+
WHEN state = 'approved' THEN 1
8+
ELSE 0
9+
END
10+
) as approved_count,
11+
SUM(amount) as trans_total_amount,
12+
SUM(
13+
CASE
14+
WHEN state = 'approved' THEN amount
15+
ELSE 0
16+
END
17+
) as approved_total_amount
18+
FROM Transactions
19+
GROUP BY month, country;

0 commit comments

Comments
 (0)