Practice Common Table Expressions (CTEs) - 19.1.2 | 19. Advanced SQL and NoSQL for Data Science | Data Science Advance
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

Common Table Expressions (CTEs)

19.1.2 - Common Table Expressions (CTEs)

Enroll to start learning

You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

What does CTE stand for?

💡 Hint: Think of temporary results in SQL.

Question 2 Easy

Write a simple CTE to get total sales from an orders table by region.

💡 Hint: Remember to use the SUM function and GROUP BY.

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What keyword is used to define a CTE?

CREATE
WITH
DEFINE

💡 Hint: Think about how we start a new SQL block.

Question 2

CTEs can reference themselves. Can they be used for hierarchical data?

True
False

💡 Hint: Consider what recursion allows us to do.

1 more question available

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Write a CTE that computes the average sales for each region and returns those above a certain threshold, while using ranking to list them.

💡 Hint: Consider how averages are calculated with GROUP BY.

Challenge 2 Hard

Create a recursive CTE that traces a product's lineage through categories and subcategories, displaying each step.

💡 Hint: Focus on constructing the category tree with proper joins.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.