Get startedGet started for free

Create a temp table

Find the Fortune 500 companies that have profits in the top 20% for their sector (compared to other Fortune 500 companies).

To do this, first, find the 80th percentile of profit for each sector with

percentile_disc(fraction) 
WITHIN GROUP (ORDER BY sort_expression)

and save the results in a temporary table.

Then join fortune500 to the temporary table to select companies with profits greater than the 80th percentile cut-off.

This exercise is part of the course

Exploratory Data Analysis in SQL

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- To clear table if it already exists; fill in name of temp table
DROP TABLE IF EXISTS ___;

-- Create the temporary table
___ ___ ___ ___ AS 
  -- Select the two columns you need; alias as needed
  SELECT ___, 
         ___(___) ___ (___) AS ___
    -- What table are you getting the data from?
    ___ ___
   -- What do you need to group by?
   ___ ___ ___;
   
-- See what you created: select all columns and rows from the table you created
SELECT * 
  FROM ___;
Edit and Run Code