SQL Consulta temporal


Ejemplo

Se comportan de la misma manera que las subconsultas anidadas pero con una sintaxis diferente.

WITH ReadyCars AS (
  SELECT *
  FROM Cars
  WHERE Status = 'READY'
)
SELECT ID, Model, TotalCost
FROM ReadyCars
ORDER BY TotalCost;
CARNÉ DE IDENTIDAD Modelo Coste total
1 Ford F-150 200
2 Ford F-150 230

Sintaxis de subconsulta equivalente

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