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.
Latihan ini adalah bagian dari kursus
Exploratory Data Analysis in SQL
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
-- 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 ___;