select min(id),max(id) from table 该如何优化 ~

2016年3月5日,华为面试有这样一个题目 

(I) select min(id),max(id) from table; 

(II) select min(id) from table; select max(id) from table; 

问这两个效率哪个高,是否有优化的可能性。百度一下,看到别人也有这个问题。

结果就是 (I) 无法走索引,效率很低。(II) 的效率会高很多。

而且推荐用

select 
    (select min(id) from table) min,  
    (select max(id) from table) max 
from dual


如下内容是转载。

大量的SQL优化案例:
http://blog.csdn.net/robinson1988/article/category/621201


2011,7/20去支付宝面试开发DBA,面试官问了这样一个题目 select min(id),max(id) from table; 他们说 是一个 很经典的案例 呵呵 我现在测试一把  


SQL>  select * from v$version where rownum<2;  
  
BANNER  
--------------------------------------------------------------------------------  
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  
SQL>  create table test as select * from dba_objects;  
  
Table created.  
  
SQL> create index i_object_id on test(object_id);  
  
Index created.  

SQL> select max(object_id),min(object_id) from test;  
  
MAX(OBJECT_ID) MIN(OBJECT_ID)  
-------------- --------------  
         74644              2  

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值