SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed

New conversation

What can I help with?

Ask about this page, get a hint on a challenge, or explore SQL concepts.

I know what's on this page and can give answers grounded in SQL Boy content.

Current page

Advanced

/blog/topics/advanced

Usage status will load after login
SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

Advanced SQL

Advanced query patterns

Use this path when you are moving beyond beginner SELECT queries into CTEs, window functions, and conditional logic.

Back to BlogPerformanceAnalyticsData PrepSchemaSecurity

Best For

Use this topic path when the bottleneck looks like one of these

When a query is logically correct but hard to reason about step by step
When you need ranking, running totals, or partition-level analytics without collapsing rows
When multi-stage transformations are clearer as named steps instead of nested subqueries
When reporting logic depends on CASE, window frames, or recursive traversal patterns

Reading Order

A practical way to move through this cluster

You do not have to read these in order, but this sequence is the fastest path from performance fundamentals into real query-tuning decisions.

1

Mastering CTEs: Writing Cleaner, Better SQL

Start with the idea of turning one long query into readable, named steps.

2

Mastering Recursive CTEs: The Inception of SQL

Then extend that mental model into recursion for hierarchies, sequences, and graph-like traversal.

3

Understanding SQL Window Functions: A Visual Guide

Move into ranking, running totals, and partition-level analytics while preserving every row.

4

SQL Window Frames: ROWS vs RANGE

Deepen the window-function model by learning the frame rules that cause many subtle reporting bugs.

5

SQL Conditional Aggregation: Beyond Basic GROUP BY

Use CASE inside aggregates to build denser analytical queries and dashboard-style outputs.

6

SQL CASE Statements: Adding Logic to Your Queries

Finish with the CASE patterns that underpin classification, branching logic, and many reporting queries.

Practice Challenges

Use these challenge pages for faster reps on the same concept cluster

Topic hubs are better for structured reading. Challenge pages are better when you want to switch from reading into hands-on practice without leaving the concept area entirely.

Products Never Ordered

Medium

Find products that never appear in the order table without being fooled by missing or duplicate order rows.

Open challenge

Second Highest Salary

Medium

Find the second distinct highest salary without accidentally returning the same maximum twice.

Open challenge

Consecutive Numbers

Hard

Find values that appear in at least three consecutive rows instead of merely appearing three times anywhere in the table.

Open challenge

Rising Temperature

Medium

Compare each weather row with the previous day and return only the IDs where temperature increased day over day.

Open challenge

Patients With Condition

Easy

Match patients whose condition list contains a Type I diabetes code without being fooled by partial code overlaps.

Open challenge

Rank Scores

Medium

Assign tied scores the same rank while keeping the next rank consecutive with no gaps.

Open challenge

Exchange Seats

Medium

Swap every pair of adjacent seat IDs while leaving the final row untouched if the seat count is odd.

Open challenge

Trips and Users

Hard

Compute daily cancellation rate after excluding any trip where either the client or driver is banned.

Open challenge

Percentage of Users Attended

Medium

Calculate contest participation rate by dividing each contest’s registrations by the total user base, not by contest-local counts.

Open challenge

Monthly Transactions I

Medium

Roll monthly transaction reporting into one query while splitting total volume from approved volume by country.

Open challenge

Immediate Food Delivery II

Medium

Measure what share of customers got an immediate delivery on their first-ever order instead of across all orders.

Open challenge

Game Play Analysis IV

Medium

Compute next-day retention by checking whether each player returned on the day after their first login.

Open challenge

Investments in 2016

Medium

Sum 2016 investment value only for policyholders who meet one duplicate condition and one uniqueness condition at the same time.

Open challenge

Last Person to Fit in the Bus

Medium

Use a running total to find the last passenger whose cumulative weight still stays under the bus limit.

Open challenge

Product Price at a Given Date

Medium

Reconstruct each product’s price as of a snapshot date, including products that had not changed yet and still use the default price.

Open challenge

Capital Gain/Loss

Medium

Calculate per-stock capital gain or loss by treating buys as cash outflows and sells as cash inflows before summing them.

Open challenge

Friend Requests I: Overall Acceptance Rate

Medium

Calculate overall friend request acceptance rate while separating request volume from accepted pairs cleanly.

Open challenge

Tree Node

Medium

Classify each tree node as root, inner, or leaf based on whether it has a parent and whether it is referenced by children.

Open challenge

Customers Who Bought All Products

Medium

Return only the customers whose distinct purchased product set covers every product listed in the catalog.

Open challenge
2026-02-06
9 min read

SQL Window Frames: ROWS vs RANGE

Learn how ROWS and RANGE window frames change results, avoid hidden pitfalls, and build correct moving calculations with clear, runnable examples.

Read article
2026-01-21
8 min read

SQL Conditional Aggregation: Beyond Basic GROUP BY

Turn multiple queries into one with conditional aggregation. Learn how CASE WHEN inside aggregate functions creates powerful single-query reports and pivot tables.

Read article
2025-12-14
6 min read

Mastering Recursive CTEs: The Inception of SQL

Unlock the power of WITH RECURSIVE. Learn how to traverse hierarchies, generate continuous dates, and solve graph problems directly in SQL.

Read article
2025-11-29
12 min read

SQL CASE Statements: Adding Logic to Your Queries

Learn how to add conditional logic to your SQL queries using CASE statements. Transform data and categorize results with ease.

Read article
2025-11-27
8 min read

Mastering CTEs: Writing Cleaner, Better SQL

Stop writing nested subquery nightmares. Learn how to use Common Table Expressions (CTEs) to make your SQL readable, modular, and powerful.

Read article
2025-11-26
7 min read

Understanding SQL Window Functions: A Visual Guide

Master ROW_NUMBER, RANK, and running totals with interactive visualizations. See exactly how window functions process your data row by row.

Read article

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed