Flink系列之:WITH clause
- 适用流、批
- 提供了一种编写辅助语句以在较大查询中使用的方法。这些语句通常称为公共表表达式 (CTE),可以被视为定义仅针对一个查询而存在的临时视图。
WITH 语句的语法为:
WITH <with_item_definition> [ , ... ]
SELECT ... FROM ...;<with_item_defintion>:with_item_name (column_name[, ...n]) AS ( <select_query> )
以下示例定义公共表表达式orders_with_total 并在GROUP BY 查询中使用它。
WITH orders_with_total AS (SELECT order_id, price + tax AS totalFROM Orders
)
SELECT order_id, SUM(total)
FROM orders_with_total
GROUP BY order_id;