它们的行为与嵌套子查询相同,但语法不同。
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