临时查询

这些行为与嵌套子查询的行为方式相同,但语法不同。

WITH ReadyCars AS (
  SELECT *
  FROM Cars
  WHERE Status = 'READY'
)
SELECT ID, Model, TotalCost
FROM ReadyCars
ORDER BY TotalCost;
ID 模型 总成本
1 福特 F-150 200
2 福特 F-150 230

等效子查询语法

SELECT ID, Model, TotalCost
FROM (
  SELECT *
  FROM Cars
  WHERE Status = 'READY'
) AS ReadyCars
ORDER BY TotalCost