#1 India's Top IT Training Institute

On Demand Courses

9 programs

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

SQL for Data Analytics Guide
PDF Downloads

Download the SQL for data analytics guide PDF from Uncodemy: SELECT, joins, aggregation, CTEs and window functions, with tested examples.

Prepared by: Uncodemy trainer team Reviewed by: Uncodemy Last reviewed: 26 Oct 2026
Query Clause Order
1
SELECTChoose columns and calculations.
2
FROM / JOINChoose tables and how they connect.
3
WHEREFilter rows before grouping.
4
GROUP BYCollapse rows into groups.
5
HAVINGFilter groups after aggregation.
6
ORDER BY / LIMITSort the result and return the first rows.

Quick Answer

This page offers Uncodemy's SQL for data analytics guide as a PDF download. It covers the SQL patterns analysts use every day: selecting and filtering, aggregating, joining tables, using CTEs and checking results. Examples use a small orders database so you can try them in SQLite, MySQL or PostgreSQL with minor changes.

Download

SQL for Data Analytics Guide PDF

The download below is its own file. It covers the everyday SQL patterns, safe joins, CTEs, reliable habits, common mistakes and NULL handling, with worked examples.

1 PDF Available
PDF 01 SQL Guide

SQL for Data Analytics Guide

Selecting, aggregating, joins, left joins, CTEs, clause order, reliable habits, common mistakes and how NULL values behave.

PDF Free Oct 2026
Download PDF
01

Why SQL is central to analytics

Most business data lives in relational databases, and SQL is the language used to ask those databases questions. Even when the final result is a dashboard or a notebook, the data usually reaches it through a SQL query. Analysts who write SQL well can answer questions on their own, check numbers directly at the source and avoid waiting for someone else to produce a file. SQL is also relatively compact: a small number of ideas, applied carefully, cover the large majority of everyday analysis.

02

The example database

The examples below use three small tables. customers has customer_id, name and city. orders has order_id, customer_id, order_date, status and order_total. order_items has order_id, product, quantity and unit_price. Each customer can place many orders and each order can contain many items. Always start by understanding the grain of each table: here customers has one row per customer, orders one row per order and order_items one row per product line.

03

Selecting, filtering and sorting

The basics: choose columns, filter rows and sort. Dates are stored as text in ISO format in this example.

SELECT order_id, customer_id, order_date, order_total
FROM orders
WHERE status <> 'cancelled'
  AND order_date >= '2026-01-01'
ORDER BY order_total DESC
LIMIT 10;
04

Aggregating with GROUP BY and HAVING

Count orders and sum revenue by customer, keeping only customers with more than two orders.

SELECT customer_id,
       COUNT(*)         AS orders,
       SUM(order_total) AS revenue
FROM orders
WHERE status <> 'cancelled'
GROUP BY customer_id
HAVING COUNT(*) > 2
ORDER BY revenue DESC;
05

Joins: combining tables

A join connects rows from two tables using a matching column. An inner join keeps only rows that match on both sides. A left join keeps every row from the left table and fills missing matches with nulls, which makes it the right choice when you want to include customers with no orders. The biggest danger with joins is changing the number of rows without noticing. Joining orders to order_items repeats each order once per item, so summing order_total after that join overstates revenue. Before trusting a result, count rows before and after each join and make sure you understand why they changed.

06

Left join to find customers without orders

Returns customers who never placed a non-cancelled order.

SELECT c.customer_id, c.name, c.city
FROM customers c
LEFT JOIN orders o
       ON o.customer_id = c.customer_id
      AND o.status <> 'cancelled'
WHERE o.order_id IS NULL;
07

A CTE to build a calculation in steps

A common table expression names an intermediate result, which makes long queries easier to read. Here we compute revenue per customer, then compare each customer with the average.

WITH customer_revenue AS (
    SELECT customer_id, SUM(order_total) AS revenue
    FROM orders
    WHERE status <> 'cancelled'
    GROUP BY customer_id
)
SELECT customer_id,
       revenue,
       ROUND(revenue - (SELECT AVG(revenue) FROM customer_revenue), 2) AS vs_average
FROM customer_revenue
ORDER BY revenue DESC;
08

SQL clause order and what each does

Written order Clause Purpose
1 SELECT Choose columns and calculations
2 FROM / JOIN Choose tables and how they connect
3 WHERE Filter rows before grouping
4 GROUP BY Collapse rows into groups
5 HAVING Filter groups after aggregation
6 ORDER BY Sort the result
7 LIMIT Return only the first rows
09

Reliable SQL habits — and common SQL mistakes

Habits that make your SQL reliable

  • Write the grain of the result in a comment before you start.
  • Use clear aliases and consistent formatting.
  • Filter early and select only the columns you need.
  • Check row counts and totals against a trusted number.
  • Test with a small, known case where you can verify the answer by hand.
  • Save queries in a file with notes on definitions.

Common SQL mistakes

  • Filtering a left join in WHERE and turning it into an inner join by accident.
  • Counting rows instead of distinct entities after a join.
  • Using SELECT star in reports, which breaks when columns change.
  • Forgetting nulls: comparisons with NULL are not true or false but unknown.
  • Dividing integers and losing decimals; multiply by 1.0 or cast.
10

How to practise

Create a small database of your own, or use a sample database, and write ten questions of increasing difficulty: counts, filters, grouping, joins, top N per group, running totals. Solve each, then explain the grain and the row count of your answer. Return to the same questions after a week and rewrite them more cleanly. Daily short practice beats long occasional sessions.

11

Reading someone else's query

A valuable analyst skill is reading and understanding existing SQL. Start at the FROM clause to see the tables and joins, then read WHERE for the filters, then GROUP BY to find the grain of the result, and finally the SELECT list to see what is calculated. Run pieces separately: execute a CTE alone, check its rows and move on. Add comments as you learn what each part does. This approach lets you maintain a query written by a colleague without rewriting it from scratch.

12

Handling NULL values

Situation What happens What to do
Compare with NULL using = Never true Use IS NULL or IS NOT NULL
Aggregate with NULLs SUM and AVG ignore NULLs; COUNT(column) skips them, COUNT(*) does not Decide whether to treat NULL as zero
Arithmetic with NULL Result is NULL Use COALESCE to give a default
Join on a NULL key Rows with NULL keys do not match Check for NULL keys before joining

Learn with a trainer

Ready to learn SQL for analysis with a trainer? Explore Uncodemy's Data Analytics course and learn from industry trainers.

View Course
About these PDFs: These PDFs are study material for learning and revision. They are not a certificate, a degree or a promise of a job, and technology changes, so check official documentation for the latest details. Spot an error? Write to info@uncodemy.com and the trainer team will review it.
FAQ

Frequently Asked Questions

What SQL should a data analyst know?
Selecting and filtering, aggregation with GROUP BY and HAVING, joins, subqueries, CTEs and window functions cover most analyst work.
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping. HAVING filters groups after aggregation.
Why did my total increase after a join?
A one-to-many join repeats rows from the first table. Summing a column from that table afterwards double counts, so check the grain and aggregate before joining when needed.
What is a CTE?
A common table expression is a named temporary result defined with WITH, used to break a complex query into readable steps.
How can I practise SQL for free?
Install SQLite or a free database, create sample tables or use public sample databases, and solve questions of increasing difficulty.
Are these PDFs free to download?
Yes, the PDF is free to download. A short form asks for your details before the download starts.