Study - Problems(IT)/LeetCode - SQL
1193.Monthly Transactions
Dev.D
2024. 11. 16. 18:59
* Probelm
Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.
Return the result table in any order.
* Solution
# Write your MySQL query statement below Select DATE_FORMAT(trans_date, '%Y-%m') AS month, country, COUNT(*) AS trans_count, sum(state='approved') as approved_count, SUM(amount) AS trans_total_amount, SUM(IF(state = 'approved',amount,0)) AS approved_total_amount FROM Transactions GROUP BY 1,2; |