Aan de slagGa gratis aan de slag

Mean and Median

Compute the mean (avg()) and median assets of Fortune 500 companies by sector.

Use the percentile_disc() function to compute the median:

percentile_disc(0.5) 
WITHIN GROUP (ORDER BY column_name)

Deze oefening maakt deel uit van de cursus

Exploratory Data Analysis in SQL

Cursus bekijken

Oefeninstructies

  • Select the mean and median of assets.
  • Group by sector.
  • Order the results by the mean.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- What groups are you computing statistics by?
SELECT ___,
       -- Select the mean of assets with the avg function
       ___ AS mean,
       -- Select the median
       ___(___) ___ ___ (___ ___ ___) AS median
  FROM fortune500
 -- Computing statistics for each what?
 GROUP BY ___
 -- Order results by a value of interest
 ORDER BY ___;
Code bewerken en uitvoeren