I need the time difference between two datestamps in hours and need to arrange them in descending order to get the median
SELECT "fulfillmentshistories"."fulfillmentid" as "Fulfillment ID" FROM FULFILLMENTHISTORIES
WHERE (Fulfillments."status" IN ('paid','delivered') AND (DATE("fulfillmenthistories"."createdAt") BETWEEN DATE('{{startDate}}') AND DATE('{{endDate}}')))
union
SELECT DATEDIFF(HOUR, 'startDate'-'endDate') as DATEDIFF;
ORDER BY DATEDIFF, DESC
This is what I tried please help
SELECT "fulfillmentshistories"."fulfillmentid" as "Fulfillment ID" FROM FULFILLMENTHISTORIES
WHERE (Fulfillments."status" IN ('paid','delivered') AND (DATE ("fulfillmenthistories"."createdAt") BETWEEN DATE('{{startDate}}') AND DATE('{{endDate}}')))
union
SELECT DATEDIFF(HOUR, 'startDate'-'endDate') as DATEDIFF;
ORDER BY DATEDIFF, DESC
Error running query: syntax error at or near "ORDER" LINE 5: ORDER BY DATEDIFF, DESC ^