欢迎投稿

今日深度:

oracle 性能优化操作十二: 用Case语句合并多重扫

oracle 性能优化操作十二: 用Case语句合并多重扫描,oraclecase


我们常常必须基于多组数据表计算不同的聚集。例如下例通过三个独立查询:

select count(*) from emp where sal<1000;

select count(*) from emp where sal between 1000 and 5000;

select count(*) from emp where sal>5000;

这样我们需要进行三次全表查询,但是如果我们使用case语句:

select 

count (sale when sal <1000

then 1 else null end)              count_poor,

count (sale when between 1000 and 5000

then 1 else null end)              count_blue_collar,

count (sale when sal >5000

then 1 else null end)              count_poor

from emp;

这样查询的结果一样,但是执行计划只进行了一次全表查询。

www.htsjk.Com true http://www.htsjk.com/shujukunews/5722.html NewsArticle oracle 性能优化操作十二: 用Case语句合并多重扫描,oraclecase 我们常常必须基于多组数据表计算不同的聚集。例如下例通过三个独立查询: select count(*) from emp where sal1000;select count(*) fr...
评论暂时关闭