TechaidasKit
PricingWorkspace
Sign in
Techaidas Kit logoTechaidasKit

Production-ready technical e-books, tested AI prompt packs, and architecture blueprints for software engineers and systems architects.

Products
  • Technical E-Books
  • Digital Vault & AI Prompts
  • AI Prompt Packs
  • Pricing Plans
Account
  • Sign in
  • My Library
  • Cart
  • Order History & Invoices
Support
  • Contact Support
  • Updates & Announcements
  • Frequently Asked Questions
  • Refund Policy
  • Digital Delivery & Watermarking
Legal
  • Privacy Policy
  • Terms of Service
  • Cookie Policy

© 2026 Techaidas. All rights reserved.

Payments powered by Paystack•Instant Digital Delivery
HomeData SolutionsExcelSales & Customer Analysis with SQL and Excel
Data solution · Sales & Revenue AnalyticsNo reviews yet

Sales & Customer Analysis with SQL and Excel

Turn a year of raw orders into a monthly report, product and margin analysis, customer cohorts and RFM segments: 10 steps, real data, every query included.

Tools
ExcelPostgreSQLGoogle Sheets
Buy once, keep it
$0.07One payment · lifetime access · no subscription
Read 2 free steps
Want everything? All-Access is $29 / month
Steps
10 steps
Code
6 snippets
Files
—
Level
Intermediate
Sales & Customer Analysis with SQL and Excel

Outcomes

What you'll be able to do

  • Load CSV files into PostgreSQL and design clean tables with keys and checks
  • Find and fix duplicates, blank values and messy text before analysing
  • Calculate monthly revenue, growth and running totals with window functions
  • Measure average order value, top products and gross margin by category
  • Build a customer cohort retention table
  • Segment customers with RFM scoring and compare marketing channels
  • Publish a reusable monthly report view and an Excel KPI dashboard

The project

10 steps from raw data to result

The first 2 steps are free to read. Buy it to unlock the rest.

  1. 1Meet the data and load itFreeUnderstand the four tables, create them in PostgreSQL and import the CSV files.
  2. 2Check and clean the dataFreeFind duplicate order lines, blank and messy values, then fix them and lock the table down.
  3. Build a sales view and monthly revenueCreate one reusable view of completed sales, then total revenue, orders and customers by month.
  4. Measure growth with window functionsAdd month-over-month growth and a running total to the monthly figures.
  5. Order value and top productsCalculate average and median order value by quarter and find the products that drive revenue.
  6. Gross margin by categorySee which categories actually make money, and what the November discount cost.
  7. Do customers come back? Cohort retentionGroup customers by the month of their first purchase and track how many buy again.
  8. Segment customers with RFMScore every customer on recency, frequency and spend, and turn the scores into action groups.
  9. Compare marketing channels and citiesFind which acquisition channels bring the most valuable customers, and where revenue comes from.
  10. Monthly report view and Excel dashboardSave a one-row-per-month report in the database, export it and build a KPI dashboard in Excel.

A look at the code

Meet the data and load it

Copy it and run it against the sample data.

01-create-tables.sql
CREATE TABLE products (
  product_id   text PRIMARY KEY,
  product_name text NOT NULL,
  category     text NOT NULL,
  unit_price   numeric(12,2) NOT NULL CHECK (unit_price >= 0),
  unit_cost    numeric(12,2) NOT NULL CHECK (unit_cost >= 0)
);

CREATE TABLE customers (
  customer_id         text PRIMARY KEY,
  signup_date         date NOT NULL,
  city                text,
  acquisition_channel text NOT NULL
);

CREATE TABLE orders (
  order_id    text PRIMARY KEY,
  customer_id text NOT NULL REFERENCES customers (customer_id),
  order_date  date NOT NULL,
  status      text NOT NULL CHECK (status IN ('completed', 'cancelled', 'refunded'))
);

-- No primary key yet: step 2 removes duplicate lines first.
CREATE TABLE order_items (
  order_id   text NOT NULL REFERENCES orders (order_id),
  product_id text NOT NULL REFERENCES products (product_id),
  quantity   integer NOT NULL CHECK (quantity > 0),
  unit_price numeric(12,2) NOT NULL CHECK (unit_price >= 0)
);
Read the full step

Questions

Frequently asked questions

Do I need PostgreSQL installed?

Any PostgreSQL 14 or newer works: installed locally, Docker, or a free hosted database such as Supabase or Neon. The queries use standard PostgreSQL features (window functions, FILTER, DATE_TRUNC).

Can I follow along with MySQL or SQL Server?

Most queries work with small changes. The main differences are DATE_TRUNC (use DATE_FORMAT in MySQL or DATETRUNC in SQL Server 2022), the FILTER clause (use SUM(CASE WHEN ... THEN 1 ELSE 0 END)) and the duplicate-removal query in step 2.

Is the data real?

It is a realistic simulated dataset built for learning: real-world patterns (growth, seasonality, a November discount, loyal and one-time customers) and deliberate quality problems, with no personal data about real people.

Reviews

From customers who have Sales & Customer Analysis with SQL and Excel.

Every query and formula is tested

Code in data solutions is run against the sample data before publishing, and notes call out differences between databases.