Real-World SQL for Analysts: 90 Practice Problems to Get You Job-Ready

Author: Neelesh N. Vasnani
File Type: pdf
Size: 2.8 MB
Language: English
Pages: 113

Real-World SQL for Analysts: 90 Practice Problems to Get You Job-Ready — A Practical Guide to SQL Skills for Data Analysts

Introduction

SQL is one of the most valuable technical skills for modern data analysts. Whether you are working in finance, engineering, healthcare, retail, logistics, marketing, or technology, organizations generate enormous quantities of structured data every day.

Knowing SQL syntax, however, is not the same as being job-ready. A professional analyst must be able to transform a business question into a SQL query, combine information from multiple tables, detect data-quality problems, calculate meaningful metrics, and communicate the results clearly.

That is where a practical resource such as Real-World SQL for Analysts: 90 Practice Problems to Get You Job-Ready becomes particularly useful. Instead of treating SQL as a collection of isolated commands, a problem-driven approach encourages analysts to think in terms of actual datasets, business requirements, and analytical decisions.

Real-World SQL for Analysts: 90 Practice Problems to Get You Job-Ready

Image

ImageImage

A useful SQL learning cycle looks like this:

Business Question → Data Exploration → SQL Query → Validation → Analysis → Insight → Decision

For beginners, this process builds confidence. For experienced professionals, it reinforces the analytical habits required when working with messy production data. 🚀


Background Theory

Why SQL remains essential for analysts

SQL, or Structured Query Language, is designed for interacting with relational databases. Although modern analytics environments include Python, R, spreadsheets, BI platforms, and cloud data warehouses, SQL remains the language used to retrieve and transform much of the underlying data.

A typical company may store information in tables such as:

  • customers
  • orders
  • products
  • employees
  • transactions
  • payments
  • web_events

These tables can contain millions or billions of records.

Instead of manually examining thousands of rows, an analyst can use SQL to answer questions such as:

Which products generated the most revenue last quarter?

Which customers have not purchased anything during the last 90 days?

What is the average order value by country?

Which employees are generating the highest sales?

The ability to answer these questions efficiently is what makes SQL valuable professionally.

From syntax to analytical thinking

Learning SELECT, WHERE, and ORDER BY is only the beginning.

A job-ready analyst must understand:

Data → Relationships → Conditions → Aggregation → Business Logic → Validation

For example, calculating revenue may look simple:

Revenue = Quantity × Unit Price

But real databases introduce additional questions:

  • Are cancelled orders included?
  • Are refunds deducted?
  • Is tax included?
  • Are duplicate transactions present?
  • Which currency is being used?
  • What happens when quantity is NULL?

This is why practice problems based on realistic scenarios are much more valuable than memorizing syntax alone.


Definition

What is real-world SQL analysis?

Real-world SQL analysis is the process of using SQL to retrieve, clean, transform, aggregate, compare, and interpret structured data to solve practical business or engineering problems.

It typically involves several SQL concepts:

SQL ConceptPurposeTypical Analyst Use
SELECTRetrieve columnsInspect datasets
WHEREFilter recordsFind qualifying rows
GROUP BYAggregate dataRevenue by region
HAVINGFilter groupsCustomers with high spending
JOINCombine tablesOrders + customers
CASEApply logicCustomer segmentation
SubqueriesNested analysisCompare against averages
CTEsOrganize queriesMulti-stage analysis
Window functionsAnalyze rows comparativelyRankings and trends
Date functionsHandle timeMonthly reporting

What does “job-ready” mean?

Being job-ready does not mean knowing every SQL function.

It means being able to take an unfamiliar dataset and systematically determine:

  1. What the tables represent.
  2. How tables are related.
  3. Which columns are relevant.
  4. What the business question means mathematically.
  5. 🐍 How to construct the query.
  6. How to verify the result.
  7. How to explain the result.

That analytical reasoning is often more important than remembering the exact syntax of an obscure function.


Step-by-Step SQL Problem-Solving Workflow

Step 1: Understand the business question

Never begin by writing SQL immediately.

Suppose a manager asks:

“Which customers are most valuable?”

That question is ambiguous.

Does “valuable” mean:

  • highest revenue?
  • highest profit?
  • most orders?
  • longest relationship?
  • highest average order value?

First define the metric.

Step 2: Inspect the database

Identify relevant tables and columns.

For example:

customers
---------
customer_id
customer_name
country

orders
------
order_id
customer_id
order_date
total_amount
status

The relationship is:

customers.customer_id → orders.customer_id

Step 3: Build the basic query

SELECT
    c.customer_id,
    c.customer_name,
    SUM(o.total_amount) AS total_revenue
FROM customers c
JOIN orders o
    ON c.customer_id = o.customer_id
WHERE o.status = 'Completed'
GROUP BY
    c.customer_id,
    c.customer_name;

Step 4: Rank the results

ORDER BY total_revenue DESC;

Now the highest-value customers appear first.

Step 5: Validate the output

Check:

  • Does the number of customers make sense?
  • 🐍 Are cancelled orders excluded?
  • 🐍 Are duplicates inflating revenue?
  • Are customers with no orders expected?
  • Are NULL values handled correctly?

Step 6: Convert the result into an insight

SQL produces a result. Analysis produces meaning.

For example:

“The top 10 customers generated 31% of completed-order revenue, indicating a significant concentration of revenue among a small customer segment.”

That statement is far more valuable to a decision-maker than simply displaying a SQL table.

Image

Image

ImageImage


Comparison: Basic SQL Learning vs Real-World Practice

Syntax-first learning

Traditional learning often follows this sequence:

SELECT → WHERE → GROUP BY → JOIN → Subquery

This is useful for understanding fundamentals, but it can become disconnected from real analytical work.

Problem-first learning

A practical approach reverses the process:

Business Problem → Data → Required Metric → SQL Technique → Validation → Insight

ApproachSyntax-BasedProblem-Based
Main focusCommandsBusiness questions
Learning styleMemorizationReasoning
Data complexityUsually lowRealistic
Error detectionLimitedEssential
Business contextMinimalStrong
Interview preparationModerateHigh
Professional transferModerateExcellent

Why 90 practice problems matter

A collection of 90 problems can expose an analyst to many different analytical patterns.

For example:

  • filtering
  • aggregation
  • joins
  • subqueries
  • date analysis
  • customer analysis
  • sales analysis
  • ranking
  • retention
  • segmentation
  • data cleaning
  • performance analysis

The objective should not be to memorize 90 solutions.

The objective is to recognize recurring patterns.


Diagrams, Tables, and SQL Patterns

The relational model

ImageImage

 

ImageImage

A simplified analytical database might look like:

CUSTOMERS
   │
   │ customer_id
   ▼
ORDERS
   │
   │ order_id
   ▼
ORDER_ITEMS
   │
   │ product_id
   ▼
PRODUCTS

This structure demonstrates why JOIN is fundamental.

Common SQL analytical patterns

Analytical QuestionSQL Technique
Which rows match a condition?WHERE
What is total revenue?SUM()
What is average revenue?AVG()
How many customers exist?COUNT()
Which products rank highest?RANK()
What happened last month?Date functions
Which customers exceed average spending?Subquery/CTE
Compare current vs previous monthWindow functions
Categorize customersCASE
Combine customer and order dataJOIN

Window functions

Window functions are particularly important for professional analytics.

For example:

SELECT
    customer_id,
    order_date,
    total_amount,
    SUM(total_amount) OVER (
        PARTITION BY customer_id
    ) AS customer_total
FROM orders;

Unlike GROUP BY, a window function can calculate an aggregate while keeping individual rows visible.

That makes window functions extremely useful for:

  • rankings
  • running totals
  • comparisons
  • moving averages
  • customer behavior
  • time-series analysis

Examples

Example 1: Find high-value customers

SELECT
    customer_id,
    SUM(total_amount) AS revenue
FROM orders
WHERE status = 'Completed'
GROUP BY customer_id
HAVING SUM(total_amount) > 10000
ORDER BY revenue DESC;

This identifies customers generating more than 10,000 units of revenue.

Example 2: Monthly sales

SELECT
    DATE_TRUNC('month', order_date) AS month,
    SUM(total_amount) AS revenue
FROM orders
WHERE status = 'Completed'
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY month;

The exact date function varies between PostgreSQL, SQL Server, MySQL, Oracle, and other database systems.

Example 3: Product ranking

SELECT
    product_id,
    SUM(quantity) AS units_sold,
    RANK() OVER (
        ORDER BY SUM(quantity) DESC
    ) AS sales_rank
FROM order_items
GROUP BY product_id;

This transforms raw transactions into a ranked product-performance report.


Real-World Applications

Business intelligence

SQL is frequently used behind dashboards that monitor:

  • revenue
  • profit
  • customer acquisition
  • conversion
  • inventory
  • operational KPIs

Financial analysis

Financial analysts can use SQL to investigate:

  • transaction volumes
  • expenses
  • revenue trends
  • payment failures
  • account activity
  • financial anomalies

Engineering analytics

Engineering organizations can apply SQL to:

  • equipment measurements
  • production records
  • maintenance events
  • sensor data
  • quality-control results
  • project performance

Marketing analytics

Marketing teams can analyze:

  • campaign performance
  • customer segments
  • conversion rates
  • acquisition channels
  • repeat purchases
  • customer lifetime value

Data science

SQL also serves as a foundation for machine-learning workflows.

Before a model is trained, analysts and data scientists often need to create a reliable analytical dataset.

A simplified pipeline is:

Database → SQL Transformation → Feature Dataset → Python/R → Model → Evaluation


Common Mistakes

Using SELECT * everywhere

Although convenient during exploration, SELECT * can retrieve unnecessary columns and make analytical queries harder to understand.

Prefer:

SELECT customer_id, customer_name, country
FROM customers;

Incorrect joins

An incorrect join can silently multiply rows and produce completely wrong results.

For example, joining tables without understanding their cardinality can cause revenue to appear several times larger than reality.

⚠️ Always understand the relationship between tables before joining them.

Filtering at the wrong stage

There is an important difference between:

WHERE

and:

HAVING

WHERE filters rows before aggregation.

HAVING filters groups after aggregation.

Ignoring NULL values

NULL is not the same as zero.

For example:

AVG(score)

may behave differently from what a beginner expects when missing values exist.

Forgetting duplicate records

Production databases may contain duplicate events, repeated imports, or multiple records representing the same business event.

Always investigate unexpected counts.


Challenges & Solutions

ChallengeSolution
Large datasetsFilter early and select necessary columns
Complicated joinsDraw the table relationships first
Duplicate rowsCheck keys and join cardinality
Missing valuesDefine explicit NULL handling
Slow queriesInspect indexes and query plans
Confusing logicBreak queries into CTEs
Inconsistent datesStandardize date/time handling
Wrong metricsDefine business logic before coding

Query performance

A correct SQL query can still be inefficient.

For large datasets, analysts should understand concepts such as:

  • indexes
  • execution plans
  • partitioning
  • predicate filtering
  • query pruning
  • aggregation cost
  • join strategies

Modern cloud warehouses may also charge based on data processed, making efficient SQL both a technical and financial consideration. 💡


Case Study: E-Commerce Revenue Analysis

Imagine an international e-commerce company operating in the United States, Canada, the United Kingdom, Australia, and Europe.

The company wants to identify regions with strong sales but poor customer retention.

Stage 1: Revenue

The analyst calculates regional revenue:

SELECT
    c.country,
    SUM(o.total_amount) AS revenue
FROM customers c
JOIN orders o
    ON c.customer_id = o.customer_id
WHERE o.status = 'Completed'
GROUP BY c.country
ORDER BY revenue DESC;

Stage 2: Repeat customers

The analyst then counts customers with multiple completed orders.

SELECT
    customer_id,
    COUNT(*) AS order_count
FROM orders
WHERE status = 'Completed'
GROUP BY customer_id
HAVING COUNT(*) > 1;

Stage 3: Business interpretation

Suppose one region generates excellent first-time sales but has a low repeat-purchase rate.

The SQL result alone does not solve the business problem.

The analyst might recommend investigating:

  • shipping experience
  • pricing
  • product quality
  • customer support
  • competitor activity
  • return policies

This illustrates the central lesson:

SQL finds patterns; analysts explain why those patterns matter.


Essential Tips

Build a SQL portfolio

Create projects based on realistic datasets.

Good portfolio projects include:

  • e-commerce analytics
  • financial transactions
  • logistics
  • employee analytics
  • marketing campaigns
  • manufacturing
  • customer retention

Practice without immediately checking solutions

When solving a problem, first attempt it independently.

If you get stuck, identify the missing concept rather than simply copying the answer.

Learn multiple ways to solve a problem

For example, a problem might be solved using:

  • a subquery
  • a CTE
  • a window function
  • conditional aggregation

Comparing approaches develops deeper SQL intuition.

Learn database-specific differences

SQL is standardized, but implementations differ.

Important ecosystems include:

  • PostgreSQL
  • MySQL
  • Microsoft SQL Server
  • Oracle Database
  • SQLite
  • BigQuery
  • Snowflake

A professional analyst should know the general SQL concepts while becoming comfortable with the platform used by their organization.

Think like an interviewer

When solving a SQL interview problem, explain your reasoning.

Don’t simply produce:

SELECT ...

Explain:

“First I identify the grain of the dataset, then join customers to transactions, filter invalid records, aggregate revenue, and finally rank the customers.”

That demonstrates analytical maturity. 🧠


FAQs

Is SQL difficult for beginners?

SQL is relatively approachable because its syntax resembles natural language. The difficult part is usually not basic syntax but understanding relationships between tables, aggregation, joins, and analytical logic.

How many SQL problems should an analyst practice?

There is no magic number. However, working through a broad collection such as 90 realistic problems can expose you to many recurring patterns and provide substantially more variety than memorizing a small set of examples.

Should I learn SQL before Python?

For many data-analyst roles, SQL is an excellent first technical skill because analysts frequently need to retrieve and transform data before using Python or another analytical tool.

Are SQL joins important for data analysts?

Absolutely. Real business data is commonly distributed across multiple related tables. Understanding INNER JOIN, LEFT JOIN, and join cardinality is essential.

Are window functions necessary?

They are not required for basic SQL, but they are extremely valuable for professional analytics. Ranking, running totals, period comparisons, and customer-level calculations often become much easier with window functions.

Can SQL alone get me a data analyst job?

SQL can be one of the most important skills, but many analyst positions also expect spreadsheet skills, data visualization, statistics, communication, and business understanding. The exact requirements depend on the role.

Should I memorize SQL queries?

No. Memorize fundamental patterns and concepts instead. A strong analyst should be able to reconstruct a query from the business requirement.

What makes a SQL practice problem realistic?

A realistic problem has context, imperfect data, relationships between tables, a measurable objective, and a result that could influence a business or engineering decision.


Conclusion

Real-World SQL for Analysts: 90 Practice Problems to Get You Job-Ready represents an important idea in SQL education: becoming proficient requires more than memorizing commands.

The strongest analysts learn to move from a vague business question to a precise analytical definition, discover the correct data, construct a reliable query, validate the result, and communicate the insight.

The progression can be summarized as:

SQL Syntax → Query Construction → Data Reasoning → Analytical Thinking → Business Insight 🚀

For students, realistic practice problems provide a bridge between classroom exercises and professional work. For experienced engineers and analysts, they provide an opportunity to strengthen query design, performance awareness, and analytical reasoning.

Ultimately, SQL is not simply a database language. It is a powerful tool for asking structured questions about the world of data.

And when those questions are connected to realistic problems, SQL practice becomes much more than coding—it becomes professional analytical training.

Unlock exclusive content
Enjoy all premium content by watching a short ad
Preparing ad...
BY ADX360