select in_time from work_task
where (state=190) and in_time>to_date(to_char(add_months(sysdate,-12),'yyyy-mm'),'yyyy-mm') and rownum<=1 order by in_time desc查出的数据是:
2010-03-23 17:31:17删除rownum<=1后查出来的数据是
2010-03-23 22:39:33
2010-03-23 17:43:31
2010-03-23 17:31:17为什么有加rownum<=1时,不是查出2010-03-23 22:39:33??
先order by,再取rownum<=1。select in_time from
(select in_time,rownum rn from work_task
where (state=190) and in_time>to_date(to_char(add_months(sysdate,-12),'yyyy-mm'),'yyyy-mm') order by in_time desc)
where rn<=1;
select * from(
select in_time from work_task
where (state=190) and in_time>to_date(to_char(add_months(sysdate,-12),'yyyy-mm'),'yyyy-mm') order by in_time desc) where rownum<=1
select to_date('2010-03-23 22:39:33','yyyy-mm-dd hh24:mi:ss') dd from dual union all
select to_date('2010-03-23 17:43:31','yyyy-mm-dd hh24:mi:ss') from dual union all
select to_date('2010-03-23 17:31:17','yyyy-mm-dd hh24:mi:ss') from dual)
select *
from (select * from t_test
order by dd desc)
where rownum = 1;