臨時查詢

這些行為與巢狀子查詢的行為方式相同,但語法不同。

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