ITPub博客

首页 > 数据库 > Oracle > from 内的子查询,引发的查询问题

from 内的子查询,引发的查询问题

原创 Oracle 作者:henry_law_14 时间:2014-05-07 11:04:21 0 删除 编辑

select *
  from (select acc_id, max(tran_dt) tran_dt
          from a
         where tran_cd = '103'
         group by acc_id) z
 where exists (select null
          from b
         where b.acc_id = z.acc_id
           and b.tran_dt = z.tran_dt);

直接查询得到结果为空

create table z as
  select acc_id, max(tran_dt) tran_dt
    from a
   where tran_cd = '103'
   group by acc_id;

先建临时表,在查询,得到结果

select *
  from z
 where exists (select null
          from b
         where b.acc_id = z.acc_id
           and b.tran_dt = z.tran_dt);

--先留个痕迹,以后再查查什么问题

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29619999/viewspace-1155668/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: ORACLE ANALYZE TABLE
请登录后发表评论 登录
全部评论

注册时间:2014-04-21

  • 博文量
    34
  • 访问量
    34300