[SQL] “Most profitable company” – Forbes

SQL Interview Question from Forbes

Photo from Pixabay on Pexels

 

The dataset for this SQL interview question from Forbes contains information on 100 companies of the Forbes list. These information include the company name, sector, industry, country, sales and profits and other columns.

The goal here would be to write a query which will return the most profitable ocmpany in the financial sector. We will solve this puzzle using two approaches:

 

Approach I: Sorting

/* Approach I: Sorting */
SELECT company, sector, continent, profits
FROM forbes_global_2010_2014
WHERE sector = 'Financials'
ORDER BY profits DESC
LIMIT 1

 

Approach II: Subqueries

/* Approach II: Subqueries */
SELECT company, continent
FROM forbes_global_2010_2014
WHERE sector = 'Financials'
AND profits = (SELECT MAX(profits) FROM forbes_global_2010_2014 WHERE sector = 'Financials')

 

You can also find the complete solution and explanation of approaches used for solving this question here:

 

 

Related Images: