本文共 513 字,大约阅读时间需要 1 分钟。
在看PostgreSQL的源代码的时候,总是看到 CTE。
所谓CTE,就是 common table express。
这里有一个小例子:
WITH test(x) AS (SELECT 1 UNION SELECT 2)SELECT * FROM test;
这个是官方说明:
WITH provides a way to write auxiliary statements for use in a larger query. These statements, which are often referred to as Common Table Expressions or CTEs, can be thought of as defining temporary tables that exist just for one query.
其目的,是为了简化SQL文的书写,让它至少看上去更加有条理,更加清晰。
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2013/06/06/3120464.html,如需转载请自行联系原作者