select clase, count (clase)
from
(select flight_no , sum(amount),
case when sum(amount) < 50000000 then 'low'
when sum(amount) between 50000000 and 150000000 then 'middle'
when sum(amount) > 150000000 then 'high'
end clase
from ticket_flights tf
join flights f on tf.flight_id =f.flight_id
group by flight_no) ggg
group by clase