You are given a table named sales where each row records a single profit amount earned by a company. A company can appear in multiple rows. Your task is to find the most profitable companies based on their total profit.
First compute the total profit for each company by summing all of its profit values. Then rank the companies by total profit in descending order so that companies with the same total profit share the same rank, and the next distinct total profit value receives the immediately following rank (no gaps). Return all companies whose rank is among the top 3 distinct profit levels, so any companies tied at a qualifying rank must all be included.
Return two columns: company and total_profit. Order the result by total_profit descending, then by company ascending.