SELECT 查詢中的公用表表示式
公用表表示式支援提取較大查詢的部分。例如:
WITH sales AS (
SELECT
orders.ordered_at,
orders.user_id,
SUM(orders.amount) AS total
FROM orders
GROUP BY orders.ordered_at, orders.user_id
)
SELECT
sales.ordered_at,
sales.total,
users.name
FROM sales
JOIN users USING (user_id)