CRM System
Enterprise Sales Pipeline · Contact Management · Deal Analytics · Activity Logging

CRM Data Design

Contacts / Leads

  • id, name, company
  • source, status, value
  • owner_id, deal_id
  • last_activity, created_at

Deals / Opportunities

  • id, title, source
  • amount_value, probability
  • stage, status, owner_id
  • forecast_value, actual_value
  • created_at, close_date

Activities

  • date, rep_id, type
  • deal_id, contact_id
  • notes, minutes, outcome
  • calls, emails, meetings

Sales Team Members

  • id, name, role, region
  • quota / forecast context
  • assigned deals
  • logged activities

Pipeline History

  • deal_id
  • from_stage, to_stage
  • at, by_rep
  • movement through funnel

Contacts & Leads

Sales Pipeline Board

New
Contacted
Evaluating
Negotiating
Pending Close
Closed
Lost

Drag a deal card from one column to another to update its pipeline stage. Click the card’s Details button to open the deal detail page. Stage changes are saved to pipeline history and refresh deal/team analytics.

Deal Detail Pages

Activity Logging

Team Performance Leaderboard

``` --- ## `modelname_sales_analytics.html` ```html Sales Analytics Dashboard
Sales Analytics Dashboard
Pipeline Value · Conversion Rates · Rep Performance · Forecast vs Actual · Lead Source Effectiveness

SQL Data Model

crm_deals

  • deal_id, title, source
  • stage, status, owner_id
  • amount_value, probability
  • forecast_value, actual_value
  • created_at, close_date

crm_pipeline_history

  • deal_id
  • from_stage, to_stage
  • at, by_rep

crm_activities

  • date, rep_id, type
  • deal_id, contact_id
  • notes, minutes, outcome

crm_sales_reps

  • rep_id, rep_name
  • role, region

crm_lead_sources

  • source_id
  • source_name

Key Sales Metrics

SQL Query Library

1. Pipeline Value by Stage

/* Total potential revenue sitting in each pipeline stage. */
SELECT stage,
       COUNT(*) AS deals,
       SUM(amount_value) AS total_potential_revenue,
       SUM(amount_value * probability) AS expected_revenue
FROM crm_deals
GROUP BY stage
ORDER BY stage_rank(stage);

2. Conversion Rates Between Pipeline Stages

/* Conversion rate for each observed stage transition. */
WITH stage_events AS (
  SELECT deal_id, stage FROM crm_deals
  UNION ALL SELECT deal_id, from_stage FROM crm_pipeline_history
  UNION ALL SELECT deal_id, to_stage FROM crm_pipeline_history
),
stage_counts AS (
  SELECT stage,
         COUNT(DISTINCT deal_id) AS deals_reached
  FROM stage_events
  GROUP BY stage
),
transition_counts AS (
  SELECT from_stage,
         to_stage,
         COUNT(DISTINCT deal_id) AS deals_moved
  FROM crm_pipeline_history
  GROUP BY from_stage, to_stage
)
SELECT from_stage,
       to_stage,
       deals_moved,
       deals_reached,
       ROUND(deals_moved * 100.0 / deals_reached, 1) AS conversion_rate_pct
FROM transition_counts
JOIN stage_counts ON stage_counts.stage = from_stage
ORDER BY stage_rank(from_stage), stage_rank(to_stage);

3. Average Deal Size and Sales Cycle Length

/* Average closed deal value and days from lead creation to close. */
SELECT AVG(amount_value) AS avg_deal_size,
       AVG(DATEDAY(close_date, created_at)) AS avg_sales_cycle_days,
       COUNT(*) AS closed_deals
FROM crm_deals
WHERE status = 'Closed'
  AND close_date IS NOT NULL;

4. Sales Rep Performance Comparison

/* Rep-level performance: assigned deals, closed revenue, activity counts, conversion. */
SELECT rep_id,
       rep_name,
       role,
       COUNT(DISTINCT deal.deal_id) AS assigned_deals,
       COUNT(DISTINCT CASE WHEN deal.status = 'Closed' THEN deal.deal_id END) AS closed_deals,
       SUM(CASE WHEN deal.status = 'Closed' THEN deal.actual_value ELSE 0 END) AS closed_revenue,
       SUM(forecast_value) AS forecast_revenue,
       (SELECT COUNT(*) FROM crm_activities WHERE rep_id = rep.rep_id) AS logged_activities,
       (SELECT COUNT(*) FROM crm_activities WHERE rep_id = rep.rep_id AND activity_type = 'Call') AS calls,
       (SELECT COUNT(*) FROM crm_activities WHERE rep_id = rep.rep_id AND activity_type = 'Email') AS emails,
       (SELECT COUNT(*) FROM crm_activities WHERE rep_id = rep.rep_id AND activity_type = 'Meeting') AS meetings,
       ROUND(
         COUNT(DISTINCT CASE WHEN deal.status = 'Closed' THEN deal.deal_id END) * 100.0 /
         NULLIF(COUNT(DISTINCT deal.deal_id), 0),
         1
       ) AS conversion_pct
FROM crm_deals AS deal
JOIN crm_sales_reps AS rep ON deal.owner_id = rep.rep_id
GROUP BY rep_id, rep_name, role
ORDER BY closed_revenue DESC;

5. Forecast vs Actual Closed Deals This Quarter

/* Forecast revenue vs actual revenue for deals closed in the current quarter. */
SELECT CASE
         WHEN close_date >= '2026-04-01' AND close_date < '2026-07-01' THEN 'Q2 2026'
       END AS quarter_label,
       COUNT(*) AS closed_deals,
       SUM(forecast_value) AS forecast_revenue,
       SUM(actual_value) AS actual_revenue,
       SUM(actual_value) - SUM(forecast_value) AS revenue_variance,
       ROUND(
         (SUM(actual_value) - SUM(forecast_value)) * 100.0 /
         NULLIF(SUM(forecast_value), 0),
         1
       ) AS variance_pct
FROM crm_deals
WHERE status = 'Closed'
  AND close_date >= '2026-04-01'
  AND close_date < '2026-07-01'
GROUP BY quarter_label;

6. Lead Source Effectiveness

/* Which lead sources produce the best conversion and revenue? */
SELECT source_name,
       COUNT(*) AS lead_count,
       COUNT(DISTINCT CASE WHEN deal.status = 'Closed' THEN deal.deal_id END) AS closed_deals,
       ROUND(
         COUNT(DISTINCT CASE WHEN deal.status = 'Closed' THEN deal.deal_id END) * 100.0 /
         NULLIF(COUNT(*), 0),
         1
       ) AS conversion_pct,
       AVG(amount_value) AS avg_deal_size,
       SUM(CASE WHEN deal.status = 'Closed' THEN deal.actual_value ELSE 0 END) AS closed_revenue
FROM crm_deals AS deal
JOIN crm_lead_sources AS source ON deal.source = source.source_name
GROUP BY source_name
ORDER BY closed_revenue DESC;

Analytics Charts

Pipeline Potential Revenue by Stage
Stage-to-Stage Conversion Rates
Forecast vs Actual Revenue — Q2 2026
Lead Source Effectiveness