create table SalesSlips(
style_A char(1) not null,
style_B char(1) not null,
style_C char(1) not null,
tally number(3) not null);
insert into SalesSlips values('A','A','A', 2);
insert into SalesSlips values('A','A','B', 4);
insert into SalesSlips values('A','A','C', 8);
insert into SalesSlips values('A','B','A', 16);
insert into SalesSlips values('A','B','B', 30);
insert into SalesSlips values('A','B','C', 50);
insert into SalesSlips values('A','C','A', 70);
insert into SalesSlips values('A','C','B', 80);
insert into SalesSlips values('A','C','C',100);
insert into SalesSlips values('B','A','A',130);
insert into SalesSlips values('B','A','B',180);
insert into SalesSlips values('B','A','C',220);
insert into SalesSlips values('B','B','A',260);
insert into SalesSlips values('B','B','B',300);
insert into SalesSlips values('B','B','C',340);
insert into SalesSlips values('B','C','A',390);
insert into SalesSlips values('B','C','B',460);
insert into SalesSlips values('B','C','C',500);
insert into SalesSlips values('C','A','A',530);
insert into SalesSlips values('C','A','B',580);
insert into SalesSlips values('C','A','C',690);
insert into SalesSlips values('C','B','A',730);
insert into SalesSlips values('C','B','B',780);
insert into SalesSlips values('C','B','C',830);
commit;
select style_A,style_B,style_C,sum(tally) as tally
from (select Least(style_A,style_B,style_C) as style_A,
case Least(style_A,style_B,style_C)
when style_A then Least(style_B,style_C)
when style_B then Least(style_A,style_C)
when style_C then Least(style_A,style_B) end as style_B,
greatest(style_A,style_B,style_C) as style_C,
tally
from SalesSlips)
group by style_A,style_B,style_C
order by style_A,style_B,style_C;