之前同事发过一个语句,实现的功能比较简单,类似group by的分组计数功能,因为where条件有like,又无法用group by来实现。SELECT a.N0,b.N1,c.N2,d.N3,e.N4,f.N5,g.N6,h.N7,i.N8,j.N9 from (select count(*) N0 from tbl_loginfo_20141110 where keyrecord
之前同事发过一个语句,实现的功能比较简单,类似group by的分组计数功能,因为where条件有like,又无法用group by来实现。 SELECT a.N0,b.N1,c.N2,d.N3,e.N4,f.N5,g.N6,h.N7,i.N8,j.N9 from (select count(*) N0 from tbl_loginfo_20141110 where keyrecord like '0%' or keyrecord like 'GJ_0%') a, (select count(*) N1 from tbl_loginfo_20141110 where keyrecord like '1%' or keyrecord like 'GJ_1%') b, (select count(*) N2 from tbl_loginfo_20141110 where keyrecord like '2%' or keyrecord like 'GJ_2%') c, (select count(*) N3 from tbl_loginfo_20141110 where keyrecord like '3%' or keyrecord like 'GJ_3%') d, (select count(*) N4 from tbl_loginfo_20141110 where keyrecord like '4%' or keyrecord like 'GJ_4%') e, (select count(*) N5 from tbl_loginfo_20141110 where keyrecord like '5%' or keyrecord like 'GJ_5%') f, (select count(*) N6 from tbl_loginfo_20141110 where keyrecord like '6%' or keyrecord like 'GJ_6%') g, (select count(*) N7 from tbl_loginfo_20141110 where keyrecord like '7%' or keyrecord like 'GJ_7%') h, (select count(*) N8 from tbl_loginfo_20141110 where keyrecord like '8%' or keyrecord like 'GJ_8%') i, (select count(*) N9 from tbl_loginfo_20141110 where keyrecord like '9%' or keyrecord like 'GJ_9%') j; 为了了解语句的性能,我做了如下类似的测试: select * from v$version; --Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production drop table a; create table a as select * from dba_objects where rownum<=50000; begin for x in 1..6 loop insert into a select * from a; end loop; commit; end; select count(*) from a; --3200000 select bytes/1024/1024 from user_segments where segment_name='A'; --357M alter system flush shared_pool; alter system flush buffer_cache; SELECT a.N0,b.N1,c.N2,d.N3,e.N4,f.N5,g.N6,h.N7,i.N8,j.N9 from (select count(*) N0 from a where object_name like 'A%' or object_name like 'V%') a, (select count(*) N1 from a where object_name like 'B%' or object_name like 'V%') b, (select count(*) N2 from a where object_name like 'C%' or object_name like 'V%') c, (select count(*) N3 from a where object_name like 'D%' or object_name like 'V%') d, (select count(*) N4 from a where object_name like 'E%' or object_name like 'V%') e, (select count(*) N5 from a where object_name like 'F%' or object_name like 'V%') f, (select count(*) N6 from a where object_name like 'G%' or object_name like 'V%') g, (select count(*) N7 from a where object_name like 'H%' or object_name like 'V%') h, (select count(*) N8 from a where object_name like 'I%' or object_name like 'V%') i, (select count(*) N9 from a where object_name like 'J%' or object_name like 'V%') j; --58s alter system flush shared_pool; alter system flush buffer_cache; --改写后 select sum(case when object_name like 'A%' or object_name like 'V%' then 1 else 0 end) N0, sum(case when object_name like 'B%' or object_name like 'V%' then 1 else 0 end) N1, sum(case when object_name like 'C%' or object_name like 'V%' then 1 else 0 end) N2, sum(case when object_name like 'D%' or object_name like 'V%' then 1 else 0 end) N3, sum(case when object_name like 'E%' or object_name like 'V%' then 1 else 0 end) N4, sum(case when object_name like 'F%' or object_name like 'V%' then 1 else 0 end) N5, sum(case when object_name like 'G%' or object_name like 'V%' then 1 else 0 end) N6, sum(case when object_name like 'H%' or object_name like 'V%' then 1 else 0 end) N7, sum(case when object_name like 'I%' or object_name like 'V%' then 1 else 0 end) N8, sum(case when object_name like 'J%' or object_name like 'V%' then 1 else 0 end) N9 from a; --19s --对比执行计划: --前者执行计划: SQL> explain plan for 2 SELECT a.N0,b.N1,c.N2,d.N3,e.N4,f.N5,g.N6,h.N7,i.N8,j.N9 from 3 (select count(*) N0 from a where object_name like 'A%' or object_name like 'V%') a, 4 (select count(*) N1 from a where object_name like 'B%' or object_name like 'V%') b, 5 (select count(*) N2 from a where object_name like 'C%' or object_name like 'V%') c, 6 (select count(*) N3 from a where object_name like 'D%' or object_name like 'V%') d, 7 (select count(*) N4 from a where object_name like 'E%' or object_name like 'V%') e, 8 (select count(*) N5 from a where object_name like 'F%' or object_name like 'V%') f, 9 (select count(*) N6 from a where object_name like 'G%' or object_name like 'V%') g, 10 (select count(*) N7 from a where object_name like 'H%' or object_name like 'V%') h, 11 (select count(*) N8 from a where object_name like 'I%' or object_name like 'V%') i, 12 (select count(*) N9 from a where object_name like 'J%' or object_name like 'V%') j; Explained. Elapsed: 00:00:00.15 SQL> @getplan 'general,outline,starts' Enter value for plan type: PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------- Plan hash value: 2527411742 ------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 130 | 123K (1)| 00:24:46 | | 1 | NESTED LOOPS | | 1 | 130 | 123K (1)| 00:24:46 | | 2 | NESTED LOOPS | | 1 | 117 | 111K (1)| 00:22:17 | | 3 | NESTED LOOPS | | 1 | 104 | 99032 (1)| 00:19:49 | | 4 | NESTED LOOPS | | 1 | 91 | 86653 (1)| 00:17:20 | | 5 | NESTED LOOPS | | 1 | 78 | 74274 (1)| 00:14:52 | | 6 | NESTED LOOPS | | 1 | 65 | 61895 (1)| 00:12:23 | | 7 | NESTED LOOPS | | 1 | 52 | 49516 (1)| 00:09:55 | | 8 | NESTED LOOPS | | 1 | 39 | 37137 (1)| 00:07:26 | | 9 | NESTED LOOPS | | 1 | 26 | 24758 (1)| 00:04:58 | | 10 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 11 | SORT AGGREGATE | | 1 | 66 | | | |* 12 | TABLE ACCESS FULL| A | 91587 | 5903K| 12379 (1)| 00:02:29 | | 13 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 14 | SORT AGGREGATE | | 1 | 66 | | | |* 15 | TABLE ACCESS FULL| A | 137K| 8831K| 12379 (1)| 00:02:29 | | 16 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 17 | SORT AGGREGATE | | 1 | 66 | | | |* 18 | TABLE ACCESS FULL | A | 85818 | 5531K| 12379 (1)| 00:02:29 | | 19 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 20 | SORT AGGREGATE | | 1 | 66 | | | |* 21 | TABLE ACCESS FULL | A | 111K| 7158K| 12379 (1)| 00:02:29 | | 22 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 23 | SORT AGGREGATE | | 1 | 66 | | | |* 24 | TABLE ACCESS FULL | A | 86539 | 5577K| 12379 (1)| 00:02:29 | | 25 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 26 | SORT AGGREGATE | | 1 | 66 | | | |* 27 | TABLE ACCESS FULL | A | 91587 | 5903K| 12379 (1)| 00:02:29 | | 28 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 29 | SORT AGGREGATE | | 1 | 66 | | | |* 30 | TABLE ACCESS FULL | A | 228K| 14M| 12379 (1)| 00:02:29 | | 31 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 32 | SORT AGGREGATE | | 1 | 66 | | | |* 33 | TABLE ACCESS FULL | A | 87981 | 5670K| 12379 (1)| 00:02:29 | | 34 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 35 | SORT AGGREGATE | | 1 | 66 | | | |* 36 | TABLE ACCESS FULL | A | 84376 | 5438K| 12379 (1)| 00:02:29 | | 37 | VIEW | | 1 | 13 | 12379 (1)| 00:02:29 | | 38 | SORT AGGREGATE | | 1 | 66 | | | |* 39 | TABLE ACCESS FULL | A | 112K| 7251K| 12379 (1)| 00:02:29 | ------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 12 - filter("OBJECT_NAME" LIKE 'J%' OR "OBJECT_NAME" LIKE 'V%') 15 - filter("OBJECT_NAME" LIKE 'I%' OR "OBJECT_NAME" LIKE 'V%') 18 - filter("OBJECT_NAME" LIKE 'H%' OR "OBJECT_NAME" LIKE 'V%') 21 - filter("OBJECT_NAME" LIKE 'G%' OR "OBJECT_NAME" LIKE 'V%') 24 - filter("OBJECT_NAME" LIKE 'F%' OR "OBJECT_NAME" LIKE 'V%') 27 - filter("OBJECT_NAME" LIKE 'E%' OR "OBJECT_NAME" LIKE 'V%') 30 - filter("OBJECT_NAME" LIKE 'D%' OR "OBJECT_NAME" LIKE 'V%') 33 - filter("OBJECT_NAME" LIKE 'C%' OR "OBJECT_NAME" LIKE 'V%') 36 - filter("OBJECT_NAME" LIKE 'B%' OR "OBJECT_NAME" LIKE 'V%') 39 - filter("OBJECT_NAME" LIKE 'A%' OR "OBJECT_NAME" LIKE 'V%') --后者执行计划: SQL> explain plan for 2 select 3 sum(case when object_name like 'A%' or object_name like 'V%' then 1 else 0 end) N0, 4 sum(case when object_name like 'B%' or object_name like 'V%' then 1 else 0 end) N1, 5 sum(case when object_name like 'C%' or object_name like 'V%' then 1 else 0 end) N2, 6 sum(case when object_name like 'D%' or object_name like 'V%' then 1 else 0 end) N3, 7 sum(case when object_name like 'E%' or object_name like 'V%' then 1 else 0 end) N4, 8 sum(case when object_name like 'F%' or object_name like 'V%' then 1 else 0 end) N5, 9 sum(case when object_name like 'G%' or object_name like 'V%' then 1 else 0 end) N6, 10 sum(case when object_name like 'H%' or object_name like 'V%' then 1 else 0 end) N7, 11 sum(case when object_name like 'I%' or object_name like 'V%' then 1 else 0 end) N8, 12 sum(case when object_name like 'J%' or object_name like 'V%' then 1 else 0 end) N9 13 from a; Explained. Elapsed: 00:00:00.01 SQL> @getplan 'general,outline,starts' Enter value for plan type: PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------- Plan hash value: 3918351354 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 66 | 12349 (1)| 00:02:29 | | 1 | SORT AGGREGATE | | 1 | 66 | | | | 2 | TABLE ACCESS FULL| A | 3097K| 194M| 12349 (1)| 00:02:29 | --------------------------------------------------------------------------- Note ----- - dynamic sampling used for this statement (level=2) 可以看出,前者10次全表扫描,后者1次全表扫描。从而时间上也大大降低了。由58s降低到19s。 优化这个sql主要还是思路的转换,难点在于怎样把10次全表扫描转化成1次全表扫描。 在OLAP中,可以加并行使sql速度更快。

随着互联网的发展,人们越来越依赖网络,大部分时间都在使用各种各样的网站和应用程序,这也使得我们需要记住很多账号和密码。为了方便用户的使用,很多网站提供了自动登录功能,让用户免除频繁输入账号和密码的烦恼。本文将介绍使用JavaScript实现自动登录功能的方法。一、登录流程分析在开始实现自动登录功能之前,我们需要了解整个登录流程。一般情况下,一个网站的登录流程

groupby函数的用法是“DataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=False, observed=False, dropna=True)”。groupby函数是一种常见的数据处理函数,用于对数据进行分组操作。

PHP作为一款流行的后端编程语言,在Web开发领域广受欢迎。天气预报功能是一种常见的Web应用场景,基于PHP实现天气预报功能相对简单易懂。本文将介绍如何使用PHP实现天气预报功能。一、获取天气数据API要实现天气预报功能,首先需要获取天气数据。我们可以使用第三方天气API来获取实时、准确的天气数据。目前,国内主流的天气API供应商包括免费的“心知天气”和收

Apple今日释出了Safari技术预览173版本,涵盖部分可能于Safari17推出的功能。该版本适用于macOSSonoma测试版以及macOSVentura系统,有兴趣的用户可于官方网页下载。Safari技术预览173版于设定中新增了功能标志区块,取代原先开发菜单的实验功能。该区块可让开发者快速地搜索特定功能,并以不同形式将「稳定」、「可供测试」、「预览」或「开发人员」等状态标示出来。重新设计的开发菜单可以帮助创作者更容易找到关键工具,以便建立网页、网页应用程序、其他应用程序中的网页内容、

Laravel中的流畅查询构建器是一个负责创建和运行数据库查询的界面。查询构建器可以与Laravel支持的所有数据库配合良好,并且可以用来执行几乎所有数据库操作。使用流畅的查询生成器的优点是它可以防止SQL注入攻击。它利用PDO参数绑定,您可以根据需要自由发送字符串。流畅的查询构建器支持许多方法,例如count、min、max、avg、sum,可以从表中获取汇总值。现在让我们看看如何使用流畅的查询构建器来获取选择查询中的计数。要使用流畅的查询构建器,请使用数据库外观类,如下所示useIllumi

如何在PHP中实现数据的分组和统计功能在实际的开发过程中,经常会遇到对数据进行分组和统计的需求。无论是对数据库中的数据进行分组统计,还是对数组中的数据进行操作,PHP提供了丰富的函数和方法来满足我们的需求。下面将分别演示如何在PHP中对数据库和数组数据进行分组和统计。数据库中的数据分组和统计假设我们有一个学生成绩表,表结构如下:CREATETABLE`s

GoogleColab是一个自2017年以来一直在促进Python编程的平台,它将利用Google的高级代码模型Codey引入AI编码功能。Codey基于PaLM2模型构建,对来自外部来源的大型高质量代码数据集进行了精心微调,以提高其在编码任务方面的性能。Colab即将推出的功能包括代码补全、自然语言到代码生成以及代码辅助聊天机器人。最初的重点将放在代码生成上,该功能旨在使用户能够生成更大的代码块并从注释或提示编写整个函数。这旨在减少编写重复代码的需求,允许用户专注于编程和数据科学的更复杂的方面

鸿蒙os3.0目前正在测试阶段,很快用户就将迎来新的系统体验了,那么相较于2.0版本,鸿蒙os3.0有什么功能呢?华为鸿蒙3.0包含了多屏协同、性能共享等功能,用户可以获得更加完善的协同体验,同时也能提升手机运行大型游戏或软件的流畅度。另外,它简化了小窗交互方式,并改进通知栏,带给你更为完美的体验,接下来就让小编给大家分析一下华为鸿蒙3.0新功能介绍,一起来了解一下吧。华为鸿蒙3.0功能介绍1、多屏协同:此前鸿蒙2.0可以在电脑手机之间互相切换使用,提高了用户的工作效率和使用体验,但此次的鸿蒙3


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!
