Explain SQL join types, how indexing affects query performance, and how you use common table expressions (CTEs) in data engineering work.
Use the supplied tables to demonstrate the concepts with a PostgreSQL query. Address why each join type is appropriate, how indexes could improve the query, and how the CTE structures the transformation.
Output
- One row per customer, including customers without qualifying orders
- Columns:
customer_id, customer_name, completed_order_count, completed_spend, latest_completed_order
- Order by
completed_spend descending, then customer_id ascending