IniziaInizia gratis

Insert into a temp table

While you can join the results of multiple similar queries together with UNION, sometimes it's easier to break a query down into steps. You can do this by creating a temporary table and inserting rows into it.

Compute the correlations between each pair of profits, profits_change, and revenues_change from the Fortune 500 data.

The resulting temporary table should have the following structure:

measure profits profits_change revenues_change
profits 1.00 # #
profits_change # 1.00 #
revenues_change # # 1.00

Recall the round() function to make the results more readable:

round(column_name::numeric, decimal_places)

Note that Steps 1 and 2 do not produce output. It is normal for the query result pane to say "Your query did not generate any results."

Questo esercizio fa parte del corso

Exploratory Data Analysis in SQL

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

DROP TABLE IF EXISTS correlations;

-- Create temp table 
___ ___ ___ ___ AS
-- Select each correlation
SELECT 'profits'::varchar AS measure,
       -- Compute correlations
       ___(___, ___) AS profits,
       ___(___, ___) AS profits_change,
       ___(___, ___) AS revenues_change
  FROM ___;
Modifica ed esegui il codice