您的位置:首页 > 数据库 > Oracle

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

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

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;

这样查询的结果一样,但是执行计划只进行了一次全表查询。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: