Articles → SQL SERVER → Common Table Expression (CTE) In SQL Server
Common Table Expression (CTE) In SQL Server
Purpose
Syntax
WITH <CTE_Name> AS (
<Select query>
)
Example
;WITH sales AS (
SELECT product_id, SUM(quantity * price) AS revenue
FROM orders
GROUP BY product_id
)
SELECT product_id, revenue
FROM sales
WHERE revenue > 20;
Output