设为首页 加入收藏

TOP

oracle性能优化操作十二:用Case语句合并多重扫描
2015-07-24 11:01:46 来源: 作者: 【 】 浏览:1
Tags:oracle 性能 优化 操作 十二 Case 语句 合并 多重 扫描

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

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;

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Oracle动态SQL语句 下一篇ORACLEPSU升级总结

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)