我无法获得APR,MAY,JUNE,JULE等有序格式的数据。我想显示按月排序的数据。
这是我目前正在做的事情:
SELECT (TO_CHAR (TRUNC (exec_end), 'DD-MON-YY'))
FROM tbl_dumps
WHERE exec_end >= TO_DATE (SYSDATE - 90)
GROUP BY TO_CHAR (TRUNC (exec_end), 'DD-MON-YY'),
TO_CHAR (TRUNC (exec_end), 'MON')
ORDER BY (TO_CHAR (TRUNC (exec_end), 'MON')) DESC
下面是当前输出:
01-MAY-18,
02-MAY-18,
03-MAY-18,
31-MAY-18,
O1-JUN-18,
02-JUN-18,
03-JUN-18,
04-JUN-18,
01-JUL-18,
02-JUL-18,
03-JUL-18,
26-APR-18,
27-APR-18,
28-APR-18.
这就是我希望输出的方式:
26-APR-18,
27-APR-18,
28-APR-18,
01-MAY-18,
02-MAY-18,
03-MAY-18,
31-MAY-18,
O1-JUN-18,
02-JUN-18,
03-JUN-18,
04-JUN-18,
01-JUL-18,
02-JUL-18,
03-JUL-18.
答案 0 :(得分:0)
据我了解,您可能需要
select to_char(exec_end, 'dd-mon-yy')
from tbl_dumps
where exec_end >= trunc(sysdate) - 90
order by to_char(exec_end, 'mm')
此外,由于sysdate - 90
看起来像“ 3个月前”,因此请考虑改用add_months(sysdate, -3)
。