Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
仅获取oracle sql中最近的行_Sql_Oracle - Fatal编程技术网

仅获取oracle sql中最近的行

仅获取oracle sql中最近的行,sql,oracle,Sql,Oracle,我试着简单一点 select date_created from smc_log_messages where rownum =1 order by date_created desc 它返回的日期如下 15-SEP-16 10.15.49.099000000 PM 然而,当我跑的时候 select date_created from smc_log_messages order by date_created desc 我看到的数据如下 30-SEP-16 12.39.00.

我试着简单一点

select date_created from smc_log_messages where rownum =1
order by date_created desc
它返回的日期如下

15-SEP-16 10.15.49.099000000 PM
然而,当我跑的时候

 select date_created from smc_log_messages 
    order by date_created desc
我看到的数据如下

30-SEP-16 12.39.00.006000000 AM
30-SEP-16 12.38.59.997000000 AM

因此,添加rownum基本上会影响结果。我做错什么了吗?

如果您想要最近的日期,请使用:

select max(date_created)
from smc_log_messages ;

如果需要Oracle 12C+中的最新行:

select lm.*
from smc_log_messages lm
order by lm.date_created desc
fetch first 1 row only;
在早期版本中:

select lm.*
from (select lm.*
      from smc_log_messages lm
      order by lm.date_created desc
     ) lm
where rownum = 1;

仅使用MAX功能获取最新和最热门记录: 选择最大值 从


这样就行了。

您可以直接订购desc@vkp . . . 非常感谢。