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)
Latihan ini adalah bagian dari kursus
Exploratory Data Analysis in SQL
Petunjuk latihan
- Select the mean and median of
assets. - Group by
sector. - Order the results by the mean.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
-- 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 ___;