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)