Intermediate SQL 1 : Getting Started & The Dataset
Hello everyone! Tonight in my free time, I am going to start a brand-new series on Intermediate SQL.
If you have been following my blog, you know I use SQL almost every single day at work. While Python and pandas are awesome for heavy data wrangling and machine learning, SQL is still the undisputed king when you need to pull, filter, and aggregate millions of rows directly from a data warehouse before your laptop fans start sounding like a jet engine.
I am writing this series partly to sharpen my own fundamentals and document patterns so I can remember them properly[cite: 4], and partly as a reference for anyone trying to level up from basic SELECT * FROM table queries.
Why Intermediate SQL Feels Different
When you first learn Basic SQL (SELECT, WHERE, ORDER BY, LIMIT), most practice problems feel pretty rigid. Usually, there are only one or two obvious ways to write the query and get the right answer.
Once we step into Intermediate SQL, things get way more interesting—and honestly, a bit trickier. As the problems get harder, there are suddenly many different ways to produce the exact same result.
Note: Keep in mind that any query solutions I share in this series should be treated as a reference, not the only way to answer a question. Two queries can return identical tables while being written completely differently.
At this stage, writing SQL isn’t just about getting the right numbers; it’s about writing queries that are readable for your teammates (and your future self six months from now) and don’t choke the database.
What We Will Cover in This Series
To move past the basics, we are going to break down the core building blocks that make up 80% of day-to-day analytical SQL work:
- Aggregate Functions: Summarizing data using
COUNT,SUM,MIN,MAX, andAVGalongsideGROUP BY. - Filtering Aggregations & Logic: Using
HAVINGto filter grouped results,DISTINCTfor unique values, andCASEstatements for customIF/THENlogic inside queries. - SQL Joins & Unions: Combining multiple tables together using
INNER,LEFT,RIGHT,FULL OUTER, self-joins, and stacking datasets withUNION/UNION ALL.
The Dataset: Apple Historical Stock Prices

For the first several lessons—especially while we master aggregations—we will be working with a historical Apple (AAPL) stock price dataset (originally pulled from Google Finance).
I actually really enjoy working with stock price data considering my last bonus that i get is from Stock. Financial time-series tables are super intuitive because everyone understands open, high, low, close, and volume.
In our table (tutorial.aapl_historical_stock_price), each row represents a single trading day:
| Column | Description |
|---|---|
date |
The specific trading date |
year / month |
Extracted date parts for easier grouping |
open |
Stock price when the market opened that day |
high |
Highest price reached during that day |
low |
Lowest price reached during that day |
close |
Stock price when the market closed that day |
volume |
Total number of shares traded that day |
id |
Unique row identifier |
Let’s run a quick sanity check query to inspect the table structure and see what the first few rows look like:
SELECT *
FROM tutorial.aapl_historical_stock_price
LIMIT 5;
This pulls the first 5 rows from the table so we can verify the column names and formatting without dumping thousands of rows onto our screen.
One important thing to watch out for: some data has been intentionally removed from this dataset. Just like real-world banking or production tables, you are going to run into NULL values—which will become super important once we start talking about how functions like COUNT and AVG behave when rows are missing data.
In Summary
That’s our starting line! Basic SQL teaches you how to fetch raw rows, while Intermediate SQL teaches you how to summarize, reshape, and combine them to actually answer business questions.
In the next post, we will dive straight into SQL Aggregate Functions (COUNT, SUM, MIN, MAX, and AVG) using this exact Apple stock table. See you in the next post!
“Success is the sum of small efforts, repeated day in and day out.”
– Robert Collier
Read next
-
More Data Engineering
Introduction SparkLet’s learn how to use Spark with Python by using the pyspark library! Make sure to view the video lecture explaining Spark and RDDs before continu...
-
Reader favourite
Dota 2 Patch 7.42 : Item Potency, 15-Minute Tormentors, and Day 1 Meta ShiftsDota 2 Patch 7.42 kills passive high-ground stalling, nerfs spell burst, and adds Item Potency. Here is a full breakdown plus Day 1 pick and win ra...
-
Reader favourite
How to Research Anything (Even When You Have a Full-Time Job)You don't need a PhD or endless free time to do deep research. Here is a practical system to scope questions, filter sources, and actually finish w...
-
Reader favourite Predicting BBRI Stocks with Meta’s ProphetThe IHSG so shit recently not gonna lie/ Have you ever wondered how businesses predict future sales, how weather apps forecast the temperature, or ...
-
Reader favourite
How to get your personal Dota2 DataThis is going to be a short post. This is really interesting for me personally. As a Data Scientist and avid Dota 2 player, what could be better th...
-
Reader favourite
Handling Missing ValuesMissing value in your data is pretty common in real life. In fact, the chance that at least one data point is missing increases as the data set siz...
Leave a comment