Ja ok:

select Key1, Key2, Key3, sum(f1)
from myfile
where ...
group by Key1, Key2, Key3
union
select Key1, Key2, max(x'ff'), sum(f1)
from myfile
where ...
group by Key1, Key2
union
select Key1, max(x'ff'), max(x'ff'), sum(f1)
from myfile
where ...
group by Key1
union
select max(x'ff'), max(x'ff'), max(x'ff'), sum(f1)
from myfile
where ...
order by 1, 2, 3