🚀 SQL Project Series #6: Banking Transaction Analysis 🏦
Learn how banks use SQL to analyze customer transactions, monitor account activity, detect fraud, and generate business insights.
🎯 Business Objectives
✅ Analyze customer transactions
✅ Calculate account balances
✅ Identify high-value customers
✅ Detect suspicious transactions
✅ Monitor transaction trends
✅ Analyze deposits vs withdrawals
✅ Measure customer activity
✅ Identify dormant accounts
✅ Generate banking KPIs
📂 Step 1: Create Database
CREATE DATABASE banking_db;
USE banking_db;
📂 Step 2: Create Customers Table
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(100),
gender VARCHAR(10),
city VARCHAR(50),
account_open_date DATE
);
📂 Step 3: Create Accounts Table
CREATE TABLE accounts (
account_id INT PRIMARY KEY,
customer_id INT,
account_type VARCHAR(30),
branch_name VARCHAR(100),
opening_balance DECIMAL(12,2),
FOREIGN KEY (customer_id)
REFERENCES customers(customer_id)
);
📂 Step 4: Create Transactions Table
CREATE TABLE transactions (
transaction_id INT PRIMARY KEY,
account_id INT,
transaction_date TIMESTAMP,
transaction_type VARCHAR(20),
amount DECIMAL(12,2),
FOREIGN KEY (account_id)
REFERENCES accounts(account_id)
);
📂 Step 5: Insert Sample Customers
INSERT INTO customers VALUES
(1,'Rahul Sharma','Male','Mumbai','2023-01-10'),
(2,'Priya Verma','Female','Delhi','2023-02-18'),
(3,'Amit Patel','Male','Pune','2023-04-12'),
(4,'Sneha Joshi','Female','Bangalore','2023-05-22'),
(5,'Rohan Gupta','Male','Hyderabad','2023-08-01');
📂 Step 6: Insert Sample Accounts
INSERT INTO accounts VALUES
(101,1,'Savings','Mumbai',50000),
(102,2,'Savings','Delhi',35000),
(103,3,'Current','Pune',100000),
(104,4,'Savings','Bangalore',45000),
(105,5,'Current','Hyderabad',75000);
📂 Step 7: Insert Sample Transactions
INSERT INTO transactions VALUES
(1001,101,'2025-01…
Leggi tutto →