Featured resource
2026 Tech Forecast
2026 Tech Forecast

1,500+ tech insiders, business leaders, and Pluralsight Authors share their predictions on what’s shifting fastest and how to stay ahead.

Download the forecast
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Data
Labs

Analyze Performance Metrics with Aggregates using SQL in PostgreSQL

In this Code Lab, you work through a real-world analytics scenario using a sales dataset. You explore prebuilt sales and employee tables to understand data structure and identify key fields for analysis. You apply SQL techniques such as aggregate functions, GROUP BY, HAVING, and window functions to analyze performance across regions and departments. You calculate totals, averages, rankings, and percentage-based metrics to generate insights. By the end of the lab, you produce structured, analysis-ready results suitable for dashboards and business reporting.

Lab platform
Lab Info
Level
Beginner
Last updated
Apr 17, 2026
Duration
35m

Contact sales

By clicking submit, you agree to our Privacy Policy and Terms of Use, and consent to receive marketing emails from Pluralsight.
Table of Contents
  1. Challenge

    Step 1: Explore the Sales Dataset

    Working in this lab

    Use the files under sql/ to write your queries, then click Validate on each task to check your work. ### Explore the Sales Dataset

    This step introduces the core dataset used throughout the lab.

    Before performing aggregations, you must understand the structure of the sales and employee tables and identify which columns represent measurable values versus grouping dimensions. Establishing this foundation ensures that later aggregate queries are both accurate and meaningful. info> This lab experience was developed by the Pluralsight team using Forge, an internally developed AI tool utilizing Gemini technology. All sections were verified by human experts for accuracy prior to publication. For issue reporting, please contact us.

  2. Challenge

    Step 2: Calculate Basic Aggregate Metrics

    This step introduces aggregate functions, which allows you to summarize large volumes of transactional data into meaningful metrics.

    You will calculate:

    • Total sales using SUM()
    • Average transaction value using AVG()
    • Transaction counts using COUNT()

    These metrics are foundational in analytics and reporting. They transform raw rows into insights that help answer questions like:

    • How much revenue did you generate?
    • What is the typical sale size?
    • How many transactions occurred?

    Understanding these basics is essential before moving into grouped and segmented analysis.

  3. Challenge

    Step 3: Group Data by Region and Department

    In this step, you’ll move from overall metrics to segmented analysis using GROUP BY.

    Instead of calculating a single total, you’ll break results down by business dimensions such as:

    • region
    • department

    This allows you to answer more targeted questions, such as:

    • Which regions generate the most revenue?
    • Which departments perform best?

    Grouping is a core SQL skill because it enables comparative analysis across different parts of the business.

    In this lab, you may see table aliases such as s (for sales) and e (for employees). These are shorthand references to tables.

    Column aliases (for example, total_sales) are different—they rename the output column and must match the names specified in each task.

  4. Challenge

    Step 4: Filter Aggregated Results with HAVING

    This step introduces the HAVING clause, which allows you to filter aggregated results.

    While WHERE filters rows before aggregation, HAVING filters results after aggregation. This distinction is critical when working with grouped data.

    You will use HAVING to:

    • Identify high-performing regions
    • Filter employees with significant activity
    • Refine grouped insights into actionable results

    This step helps you move from raw summaries to focused, decision-ready outputs.

  5. Challenge

    Step 5: Rank Performance with Window Functions

    In this step, you will work with window functions, which allow you to perform calculations across sets of rows without collapsing them like GROUP BY does.

    You’ll use:

    • ROW_NUMBER() to assign a unique order within groups
    • RANK() to identify top performers
    • PARTITION BY to segment rankings by region

    These functions are powerful for answering questions like:

    • Who is the top performer in each region?
    • How do employees rank within their group?

    Window functions are widely used in real-world analytics, especially for leaderboards, rankings, and comparative performance analysis.

  6. Challenge

    Step 6: Create Calculated Metrics for Insights

    In this final step, you will create calculated metrics that provide deeper analytical insight.

    Instead of just reporting totals, you will calculate:

    • Percentage of total sales by region
    • Contribution of each employee
    • Formatted outputs for readability

    These types of calculations are commonly used in dashboards and executive reports to show relative performance, not just raw values.

    By the end of this step, you will be able to transform aggregated data into polished, insight-driven results suitable for decision-making.

About the author

Pluralsight’s AI authoring technology is designed to accelerate the creation of hands-on, technical learning experiences. Serving as a first-pass content generator, it produces structured lab drafts aligned to learning objectives defined by Pluralsight’s Curriculum team. Each lab is then enhanced by our Content team, who configure the environments, refine instructions, and conduct rigorous technical and quality reviews. The result is a collaboration between artificial intelligence and human expertise, where AI supports scale and efficiency, and Pluralsight experts ensure accuracy, relevance, and instructional quality, helping learners build practical skills with confidence.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight