Mean và Median
Tính mean (avg()) và median của tài sản (assets) các công ty Fortune 500 theo từng sector.
Dùng hàm percentile_disc() để tính median:
percentile_disc(0.5)
WITHIN GROUP (ORDER BY column_name)
Bài tập này là một phần của khóa học
Phân tích Khám phá Dữ liệu bằng SQL
Hướng dẫn bài tập
- Chọn mean và median của
assets. - GROUP BY
sector. - ORDER BY kết quả theo mean.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
-- 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 ___;