Creează un tabel temporar
Găsește companiile din Fortune 500 ale căror profituri se află în primele 20% din sectorul lor (comparativ cu celelalte companii din Fortune 500).
Pentru aceasta, calculează mai întâi percentila 80 a profitului pentru fiecare sector folosind
percentile_disc(fraction)
WITHIN GROUP (ORDER BY sort_expression)
și salvează rezultatele într-un tabel temporar.
Apoi unește fortune500 cu tabelul temporar pentru a selecta companiile cu profituri mai mari decât pragul percentilei 80.
Acest exercițiu face parte din cursul
Analiza Exploratorie a Datelor în SQL
Exercițiu interactiv practic
Încearcă acest exercițiu completând acest cod de exemplu.
-- 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 ___;