Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3583591
  • 博文数量: 109
  • 博客积分: 10011
  • 博客等级: 上将
  • 技术积分: 2457
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-18 19:04
文章分类

全部博文(109)

文章存档

2011年(1)

2010年(10)

2009年(36)

2008年(62)

我的朋友

分类: Oracle

2009-12-03 13:48:12

看了几个面试题目:
有员工表empinfo
(
Fempno varchar2(10) not null pk,
Fempname varchar2(20) not null,
Fage number not null,
Fsalary number not null
);
假如数据量很大约1000万条;写一个你认为最高效的SQL,用一个SQL计算以下四种人:
fsalary>9999 and fage > 35
fsalary>9999 and fage < 35
fsalary<9999 and fage > 35
fsalary<9999 and fage < 35
每种员工的数量;
 
 
我用10万条数据测试,这样写的:
SQL> select count(*) from empinfo;
  COUNT(*)
----------
    100000
已用时间:  00: 00: 00.01
SQL> with total as (
  2       select * from empinfo
  3  )
  4  select (select count(*) from total where  fsalary>9999 and fage>35) t1,
  5   (select count(*) from total where  fsalary>9999 and fage<35) t2,
  6    (select count(*) from total where  fsalary<9999 and fage>35) t3,
  7     (select count(*) from total where  fsalary<9999 and fage<35) t4
  8  from dual ;
        T1         T2         T3         T4
---------- ---------- ---------- ----------
     89966         33       9997          2
已用时间:  00: 00: 00.06
统计信息
----------------------------------------------------------
         13  recursive calls
          0  db block gets
       2996  consistent gets
          0  physical reads
          0  redo size
        570  bytes sent via SQL*Net to client
        385  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
 
不知道大家有没有其他的方法。讨论讨论啦。。
阅读(1497) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~