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)
This exercise is part of the course
Exploratory Data Analysis in SQL
Exercise instructions
- Select the mean and median of
assets
. - Group by
sector
. - Order the results by the mean.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- 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 ___;