--■■■Lead関数を使う方法■■■
select no,RTrim(concat_area,',') as concat_area
from (select no,area,
area || ',' ||
Lead(area,1) over(partition by no order by area) || ',' ||
Lead(area,2) over(partition by no order by area) as concat_area,
min(area) over(partition by no) as Minarea
from テーブル)
where area = Minarea;
--■■■Lag関数を使う方法■■■
select no,LTrim(concat_area,',') as concat_area
from (select no,area,
Lag(area,2) over(partition by no order by area) || ',' ||
Lag(area,1) over(partition by no order by area) || ',' ||
area as concat_area,
max(area) over(partition by no) as Maxarea
from テーブル)
where area = Maxarea;
--■■■分析関数を使わない方法■■■
select no,
Rtrim(
max(decode(Rank,1,area)) || ',' ||
max(decode(Rank,2,area)) || ',' ||
max(decode(Rank,3,area)),',') as concat_area
from (select no,area,
(select count(*)+1 from テーブル b
where b.no = a.no
and b.area < a.area) as Rank
from テーブル a)
group by no
order by no;