SQL optimization Chapter VIII Case analog 8.2 max min while reading optimization

This case reference "SQL optimization core idea" (Luobing Sen, Huang Chao Zhong Jiao forward).

Have heard it was a large company of interview questions, you have any better suggestions, please leave comments. Thank you.

8.2.1 configuration data environment

drop table test1;

create table test1 as select * from dba_objects;

create index ix_test1_01 on test1(object_id);

8.2.2 SQL problem

select min(t1.object_id),max(t1.object_id) from test1 t1;

8.2.3 rewrite optimization

select min(id) as min_id,max(id) as max_id from 

(select min(t1.object_id) as id from test1 t1

union all

select max(t1.object_id)  from test1 t1);

Guess you like

Origin blog.csdn.net/songjian1104/article/details/91957862