Oracle 11g クエリを記述して、目的の結果を得るにはどうすればよいですか。具体的には、 REQUIREMENTSテーブルの最新のレコードに結合するにはどうすればよいですか?
選択基準:最新の詳細と最新の要件
with
detail as (
select 'TAXI' code, '4920' numb, 1990 dstart, 'BLUE' taxi_name from dual union all
select 'TAXI' code, '4920' numb, 2000 dstart, 'PINK' taxi_name from dual union all
select 'TAXI' code, '4920' numb, 2008 dstart, 'CYAN' taxi_name from dual),
requirement as (
select 'TAXI' code, '4920' numb, 2 seqno, 2000 rstart, 25,min_age,'CDL',permit from dual union all
select 'TAXI' code, '4920' numb, 4 seqno, 2000 rstart, 27 min_age, 'CAR' permit from dual union all
select 'TAXI' code, '4920' numb, 6 seqno, 2000 rstart, 29 min_age, 'HAZ' permit from dual union all
select 'TAXI' code, '4920' numb, 2 seqno, 2007 rstart, 24 min_age, 'CDL' permit from dual union all
select 'TAXI' code, '4920' numb, 4 seqno, 2007 rstart, 26 min_age, 'VAN' permit from dual union all
select 'TAXI' code, '4920' numb, 6 seqno, 2007 rstart, 28 min_age, 'HAZ' permit from dual
)。
select code,numb,taxi_name, dstart, ranking from (
select code, numb, taxi_name,dstart, rank() over (partition by code, numb
order by dstart desc ) ranking
from detail)
where ranking =1
収量
CODE NUMB NAME YEAR
---- ---- ----- -------
TAXI 4920 CYAN 2008
DESIRED OUTPUT
--------------------------
code numb name dstart sqno rstart min_age permit
TAXI 4920 CYAN 2008 2 2007 24 CDL
TAXI 4920 CYAN 2008 4 2007 26 VAN
TAXI 4920 CYAN 2008 6 2007 28 HAZ