Я выполняю приведенный ниже запрос, но в последнем подзапросе (пробеге) получаю следующую ошибку из-за ORDER BY
: «ORA-00907: отсутствует правая скобка», если я удаляю ORDER BY, он работаетхорошо.
SELECT /* DATE OF THE ROUTE */
{GPS}.[DateTime],
/* ROUTE DESCRIPTION */
{Route}.[Description],
/* NAME OF THE DRIVER */
{Driver}.[Name],
/* VEHICLE LICENSE PLATE */
{Vehicle}.[Registration],
/* QUANTITY OF STOPS */
(SELECT COUNT({RouteStop}.[RouteId])
FROM {RouteStop}
WHERE {RouteStop}.[RouteId] = {GPS}.[RouteId]) AS StopCount,
/* AMOUNT OF FUEL */
(SELECT SUM(FUEL.[Value])
FROM {GPS} FUEL
WHERE {GPS}.[RouteId] = FUEL.[RouteId]
AND FUEL.[EventTypeId] = 23) FuelAmount, /* Event Fuel */
/* ROUTE STARTDATETIME */
{GPS}.[DateTime] AS ROUTESTARTDATETIME,
/* ROUTE ENDDATETIME */
(SELECT ROUTEENDDATETIME.[DateTime]
FROM {GPS} ROUTEENDDATETIME
WHERE {GPS}.[RouteId] = ROUTEENDDATETIME.[RouteId]
AND ROUTEENDDATETIME.[EventTypeId] = 5 /* Event Route Completed */
AND ROWNUM = 1) AS ROUTEEND,
/* INITIAL MILEAGE */
(SELECT MILEAGEBEGIN.[Value]
FROM {GPS} MILEAGEBEGIN
WHERE {GPS}.[RouteId] = MILEAGEBEGIN.[RouteId]
AND MILEAGEBEGIN.[EventTypeId] = 21 /* Event Mileage */
AND ROWNUM = 1
ORDER BY MILEAGEBEGIN.[DateTime]
) AS INITIALMILEAGE
FROM {GPS}
INNER JOIN {Route}
ON {GPS}.[RouteId] = {Route}.[Id]
INNER JOIN {Driver}
ON {GPS}.[DriverId] = {Driver}.[Id]
INNER JOIN {Availability}
ON {Driver}.[Id] = {Availability}.[DriverId]
INNER JOIN {Vehicle}
ON {Availability}.[VehicleId] = {Vehicle}.[Id]
WHERE {GPS}.[EventTypeId] = 3 /* Event RouteStarted */
Я пытался следующим образом, но я получаю эту ошибку: "ORA-00936: отсутствует выражение".
SELECT /* DATE OF THE ROUTE */
{GPS}.[DateTime],
/* INITIAL MILEAGE */
SELECT TEST,'more test' FROM (SELECT MILEAGEBEGIN.[Value] AS TEST
FROM {GPS} MILEAGEBEGIN
WHERE {GPS}.[RouteId] = MILEAGEBEGIN.[RouteId]
AND MILEAGEBEGIN.[EventTypeId] = 21 /* Event Mileage */
ORDER BY MILEAGEBEGIN.[DateTime] ASC
)
WHERE ROWNUM = 1 AS INITIALMILEAGE
FROM {GPS}
WHERE {GPS}.[EventTypeId] = 3 /* Event RouteStarted */