with Hune as(
select 1 as Speed from dual
union select 3 from dual
union select 6 from dual
union select 9 from dual),
List as (select a.Speed,b.Speed,c.Speed,d.Speed,
e.Speed,f.Speed,g.Speed,h.Speed,
greatest(a.Speed,b.Speed)+c.Speed+
greatest(d.Speed,e.Speed)+f.Speed+
greatest(g.Speed,h.Speed) as TimeSum,
min(greatest(a.Speed,b.Speed)+c.Speed+
greatest(d.Speed,e.Speed)+f.Speed+
greatest(g.Speed,h.Speed)) over() as MinTimeSum,
to_char(a.Speed) || '分の船と' || to_char(b.Speed) || '分の船で渡る' as 行動1,
to_char(c.Speed) || '分の船で戻る' as 行動2,
to_char(d.Speed) || '分の船と' || to_char(e.Speed) || '分の船で渡る' as 行動3,
to_char(f.Speed) || '分の船で戻る' as 行動4,
to_char(g.Speed) || '分の船と' || to_char(h.Speed) || '分の船で渡る' as 行動5
from Hune a,Hune b,Hune c,Hune d,Hune e,Hune f,Hune g,Hune h
where a.Speed < b.Speed
and d.Speed < e.Speed
and g.Speed < h.Speed
and c.Speed in(a.Speed,b.Speed)
and d.Speed !=(select a.Speed from dual
union select b.Speed from dual
minus select c.Speed from dual)
and e.Speed !=(select a.Speed from dual
union select b.Speed from dual
minus select c.Speed from dual)
and f.Speed in(select a.Speed from dual
union select b.Speed from dual
minus select c.Speed from dual
union select d.Speed from dual
union select e.Speed from dual)
and g.Speed not in(select a.Speed from dual
union select b.Speed from dual
minus select c.Speed from dual
union select d.Speed from dual
union select e.Speed from dual
minus select f.Speed from dual)
and h.Speed not in(select a.Speed from dual
union select b.Speed from dual
minus select c.Speed from dual
union select d.Speed from dual
union select e.Speed from dual
minus select f.Speed from dual))
select 行動1,行動2,行動3,行動4,行動5,'合計は' || to_char(MinTimeSum) || '分' as 合計
from List
where TimeSum = MinTimeSum;