Skip to content

Commit 4fab008

Browse files
authored
Create monthly-transactions-i.sql
1 parent 483adf5 commit 4fab008

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

MySQL/monthly-transactions-i.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
SELECT Date_format(trans_date, '%Y-%m') AS month,
5+
country,
6+
Count(id) AS trans_count,
7+
Count(IF(state = 'approved', 1, NULL)) AS approved_count,
8+
SUM(amount) AS trans_total_amount,
9+
SUM(IF(state = 'approved', amount, 0)) AS approved_total_amount
10+
FROM transactions
11+
GROUP BY Date_format(trans_date, '%Y-%m'),
12+
country
13+
ORDER BY NULL

0 commit comments

Comments
 (0)