From the course: Data Engineering: dbt for SQL
Unlock this course with a free trial
Join today to access over 24,200 courses taught by industry experts.
Solution: Implementing CTEs
From the course: Data Engineering: dbt for SQL
Solution: Implementing CTEs
(upbeat music) - [Instructor] Congratulations on completing the implementing CTEs challenge. You've experienced firsthand how CTEs can significantly improve the readability of your code. Now, let's start applying CTEs to simplify the maintenance.sql file. Go to chapter4, open up the models, and open up maintenance.sql. When we open maintenance.sql, we notice a lot of repeated logic, making basic maintenance operations error-prone in its entire file. To address this, we'll rewrite the code using a CTE. Our target CTE will be the excavator readiness evaluation, since it appears in every block. Let's open maintenance_cte.sql for our work. I've copied and pasted my solution first, and I'll begin explaining it. We'll first choose a name for our CTE. In this case, I called our CTE, failing_excavators. Next, we include the repeated information and the repeated logic, specifically the excavator readiness check, into…