Common Table Expressions (CTEs)
A CTE is a temporary result set that you can reference within a SELECT, INSERT, UPDATE, or DELETE statement.
It makes complex queries easier to read and maintain.
WITH Sales_CTE AS (
SELECT employee_id, SUM(amount) as total_sales
FROM sales
GROUP BY employee_id
)
SELECT * FROM Sales_CTE WHERE total_sales > 1000;
Task:
Create a CTE named HighValue that selects orders with an amount greater than 500, then select everything from that CTE.