如何优化执行oracle查询?

时间:2018-01-23 08:44:54

标签: sql oracle11g

在oracle中,提出问题

哪个国家的人口超过加拿大但低于波兰?显示名称和人口

我这样做了。

select name,population from world 
where population > (select population from world where name='Canada') 
and population< (select population from world where name ='Poland')

还有其他优化方式吗?

1 个答案:

答案 0 :(得分:0)

这样的东西?

WITH can_pol
     AS (SELECT SUM (DECODE (name, 'Canada', population)) pop_can,
                SUM (DECODE (name, 'Poland', population)) pop_pol
           FROM world)
SELECT name, population
  FROM world, can_pol
 WHERE population > pop_can 
   AND population < pop_pol;