Project
Project
-- 5. For each month - how many customers make more than 1 deposit and 1 withdrawal
in a single month?
SELECT
customer_id,
SUM(CASE WHEN txn_type = 'deposit' THEN txn_amount ELSE txn_amount END) AS
total_amount
FROM customer_transactions
GROUP BY customer_id;
SELECT
c.customer_id,
COALESCE(SUM(txn_amount)) AS closing_balance
FROM customer_transactions c
GROUP BY c.customer_id
ORDER BY c.customer_id;
-- 7. What is the closing balance for each customer at the end of the month?
SELECT
customer_id,
EXTRACT(MONTH FROM txn_date) AS transaction_month,
SUM(CASE WHEN txn_type = 'deposit' THEN txn_amount ELSE txn_amount END) AS
total_amount
FROM customer_transactions
GROUP BY customer_id, transaction_month;
SELECT
c.customer_id,
EXTRACT(MONTH FROM txn_date) AS month,
COALESCE(SUM(txn_amount),0) AS closing_balance
FROM customer_transactions c
GROUP BY c.customer_id, month
ORDER BY c.customer_id, month;
-- 9. Find out the total deposit amount for every five days consecutive series. You
can assume 1 week = 5 days.Please show the result week wise total amount.
-- 10. Plase compare every weeks total deposit amount by the following previous
week.