【发布时间】:2015-05-14 04:19:25
【问题描述】:
我想创建一个临时表,该表又从一个查询派生以用于另一个子查询,以简化 rownum() 和按条件分区。我输入的查询如下,但它返回一个错误 t.trlr_num 无效标识符。
with t as
(select distinct
ym.trlr_num,
ym.arrdte,
ri.invnum,
ri.supnum
from rcvinv ri, yms_ymr ym
where ym.trlr_cod='RCV'
and ri.trknum = ym.trlr_num
and ym.wh_id <=50
and ym.trlr_stat in ('C','CI','R','OR')
and ym.arrdte is not null
order by ym.arrdte desc
)
select trlr_number, invnum, supnum
from
(
select
t.trlr_num, t.invnum, t.supnum,
row_number() over (partition by t.trlr_number,t.invnum order by t.arrdte) as rn
from t
)
where rn = 1;
从上面,我设置了一个条件来创建一个表 t 作为临时表,以便在下面的 select 语句中使用。但它似乎因标识符无效而出错。
【问题讨论】:
标签: sql oracle temp-tables