From the course: SQL Tips and Tricks for Data Science
Unlock the full course today
Join today to access over 23,100 courses taught by industry experts.
Common table expressions - SQL Tutorial
From the course: SQL Tips and Tricks for Data Science
Common table expressions
- [Instructor] Okay. Now we're going to take a look at common table expressions. Common table expressions are temporary structures that contain separate data than the main query. And they allow us to reference it again as a self-referencing join. This might be a little confusing. So you can think of a CTE or a common table expression like a sub query, where you define a dataset within another query, and then you can reference it from another part of the query, the outer query. Now CTEs are exactly like that. But they're also self-referencing, meaning you can do things like traverse hierarchies in your data within a single query. These little magical functions allow an incredible amount of expressiveness in your analysis. A really unique way is to use CTEs to do a hierarchy analysis. We'll do this in our demo. But to explain the idea is that when you have a hierarchy such as an employee hierarchy, where employees…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Retrieve data using SQL4m 18s
-
(Locked)
Join tables5m 44s
-
(Locked)
Filter data5m 33s
-
(Locked)
Aggregate data6m 29s
-
(Locked)
Window functions1m 54s
-
(Locked)
Subqueries4m 16s
-
(Locked)
Rolling calculations4m 48s
-
(Locked)
Analyze employee data4m 18s
-
(Locked)
Date and time functions5m 11s
-
(Locked)
Common table expressions5m 55s
-
(Locked)
Year-over-year calculations3m 26s
-
(Locked)
Finding ranks4m 9s
-
-