首页 新闻 会员 周边

一个关于相关子查询的问题?

0
悬赏园豆:100 [已关闭问题]

建表和插入数据语句:

create table t
as
select object_name ename,
mod(object_id,50) deptno,
object_id sal
from all_objects
where rownum <= 1000

用相关子查询查出每个deptno里sal最高或者最低的3个人。

select *
  from t t1
where t1.sal in (select sal
                    from (select distinct sal, deptno
                            from t b
                          where b.deptno = t1.deptno
                          order by b.deptno, b.sal desc) a
                  where rownum <= 3)
但用

 select *
  from t t1
where t1.sal in (select sal
                    from (select distinct sal, deptno
                            from t b
                         
                          order by b.deptno, b.sal desc) a
                  where rownum <= 3 and b.deptno = t1.deptno )

确可以,请问这是什么原因? 

tyrbl的主页 tyrbl | 初学一级 | 园豆:34
提问于:2009-01-13 14:30
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册