首页 > 数据库 > Oracle > from 内的子查询,引发的查询问题
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/ ,如需转载,请注明出处,否则将追究法律责任。