具有以下查询
SELECT
Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date',
device_serial as "Device Serial",
customer_name as "Customer",
error_code as 'Error Code',
resolutiom as 'Resolution'
FROM preventive_maintenance
ORDER BY `timestamp` desc
LIMIT 25
我想按“到期日”订购,该怎么办?
答案 0 :(得分:0)
只需将当前查询作为子查询即可。
SELECT
T.*
FROM
(SELECT
Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as `Due Date`,
device_serial as `Device Serial`,
customer_name as `Customer`,
error_code as `Error Code`,
resolutiom as `Resolution`
FROM preventive_maintenance
-- ORDER BY `timestamp` desc
LIMIT 25) AS T
ORDER BY T.`Due Date`
答案 1 :(得分:0)
Order By `Due Date`
需要工作。你试过了吗?如果没有,则可以使用子查询。
SELECT * FROM
(
SELECT
Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date',
device_serial as "Device Serial",
customer_name as "Customer",
error_code as 'Error Code',
resolutiom as 'Resolution'
FROM preventive_maintenance
) T
ORDER BY `Due Date`
LIMIT 25
示范
SELECT * from ( SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual union all SELECT Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date' from dual ) T order by `Due Date` LIMIT 5
| Due Date | | :------------------ | | 2019-10-27 13:16:15 | | 2019-11-26 13:16:15 | | 2020-05-05 13:16:15 | | 2020-07-01 13:16:15 | | 2020-07-01 13:16:15 |
db <>提琴here