This repository contains solutions to a SQL-based assessment designed to evaluate data analysis proficiency using relational databases.
Approach:
Identified customers with at least one savings and one investment product using joins and filters on is_regular_savings and is_a_fund. Aggregated their total deposits and sorted descending.
Approach:
Counted total transactions per customer and calculated number of active months using transaction dates. Classified into frequency categories using a CASE statement.
Approach:
Pulled the last transaction date per account, calculated days since last transaction, and filtered for inactivity greater than 365 days.
Approach:
Used a simplified formula considering transaction volume and tenure in months. Handled potential divide-by-zero and converted Kobo to Naira for final CLV estimation.
- Currency Conversion: Needed to convert Kobo to Naira by dividing by 100.
- Tenure Calculation: Used PostgreSQL
AGE()andDATE_PART()functions to calculate active months accurately. - Data Absence: Handled cases where some customers had no transactions using
LEFT JOINandCOALESCE. - Efficiency: Optimized CTEs to avoid redundant aggregations and used filtering early.
All queries are written in PostgreSQL syntax. You may need to tweak functions if using a different SQL dialect.