我正在尝试按查询结果订购 2 件这样的事情
通过“reservationStatus”,然后根据 reservationStatus 的两个字段之一。
这是我的mysql代码
SELECT rs.reservationStatus,
DATE_FORMAT(rs.dateFrom, "%d-%m-%Y %h:%i %p") AS pickupTime,
DATE_FORMAT(rs.dateTo, "%d-%m-%Y %h:%i %p") AS dropoffTime,
cu.fullName,
ve.name FROM reservation AS rs
INNER JOIN customers AS cu ON rs.CustomerID = cu.customerID
INNER JOIN vehicles AS ve ON rs.Vehicle_id = ve.Vehicles_id
WHERE rs.dateFrom <= DATE_ADD(curdate() , INTERVAL 86399 SECOND) AND rs.reservationStatus IN (1,2)
ORDER BY rs.reservationStatus, CASE WHEN rs.reservationStatus = 1 THEN rs.dateFrom ELSE rs.dateTo END ASC
这给了我一个语法错误。但是,如果我删除 rs.reservationStatus,并将案例陈述留在那里,那么它就会运行,但我看不到按应有的顺序排列的结果。
我需要的是像这样对我的结果进行排序
如何让上面的查询正确运行?