CTE — temporary named result set.
Purpose:
Example:
1WITH CustomerTotals AS (2 SELECT customer_id, SUM(amount) as total3 FROM orders4 GROUP BY customer_id5)6SELECT c.name, ct.total7FROM customers c8INNER JOIN CustomerTotals ct ON c.id = ct.customer_id9WHERE ct.total > 1000;
Benefits:
BA use: