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