select ID,連番,名称,発効年月日,失効年月日 from( select ID,連番,名称,発効年月日,失効年月日 ,row_number() over (partition by ID order by 連番 desc) rn from マスタテーブル where 発効年月日 <= trunc(sysdate) and 失効年月日 >= trunc(sysdate) ) where rn = 1 order by ID,連番;
select ID,連番,名称,発効年月日,失効年月日 from マスターテーブル a where 連番 = (select max(連番) from マスターテーブル b where a.ID = B.ID and 発効年月日 <= trunc(sysdate) and 失効年月日 >= trunc(sysdate)) order by ID,連番;
>select ID,連番,名称,発効年月日,失効年月日 >from マスターテーブル a >where 連番 = (select max(連番) > from マスターテーブル b > where a.ID = B.ID and 発効年月日 <= trunc(sysdate) and 失効年 月日 >= trunc(sysdate)) >order by ID,連番; こちらはWeher句に指定ですか・・・
>有効の定義は、発効年月日<=sysdate and 失効年月日>sysdate ということで よ >ろしいですか? はい、現時点では上記仕様との事でした。
>select a.* >from >マスタテーブル a, >( > select id,max(連番) as 連番 > from マスタテーブル > where 発効年月日<=sysdate and 失効年月日>sysdate > group by id >) b >where >a.ID=b.ID and >a.連番=b.連番