Get startedGet started for free

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."

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.

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 ___;
Edit and Run Code