Skip to content

Commit 50431e2

Browse files
committed
Upload 031
1 parent abdb21d commit 50431e2

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ ALL CONTENTS IN THIS REPO ARE FOR EDUCATIONAL PURPOSES ONLY.
7171
| 028 | [Spotify Streaming History](https://datalemur.com/questions/spotify-streaming-history) | [Solution](solutions/028_spotify_streaming_history.md) | DataLemur | Medium | |
7272
| 029 | [Consecutive Filing Years](https://datalemur.com/questions/consecutive-filing-years) | [Solution](solutions/029_consecutive_filing_years.md) | DataLemur | Hard | |
7373
| 030 | [Average Post Hiatus (Part 1)](https://datalemur.com/questions/sql-average-post-hiatus-1) | [Solution](solutions/030_average_post_hiatus_part_1.md) | DataLemur | Easy | |
74+
| 031 | [Mean, Median, Mode](https://datalemur.com/questions/mean-median-mode) | [Solution](solutions/031_mean_median_mode.md) | DataLemur | Medium | `PERCENTILE_CONT()` |
7475

7576
## Authors
7677

solutions/031_mean_median_mode.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SQL Everyday \#031
2+
3+
## Mean, Median, Mode
4+
5+
Site: DataLemur\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
You're given a list of numbers representing the number of emails in the inbox of Microsoft Outlook users. Before the Product Management team can start developing features related to bulk-deleting email or achieving inbox zero, they simply want to find the mean, median, and mode for the emails.
11+
12+
Display the output of mean, median and mode (in this order), with the mean rounded to the nearest integer. It should be assumed that there are no ties for the mode. [[Full Description](https://datalemur.com/questions/mean-median-mode)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
WITH mean AS (
19+
SELECT
20+
ROUND(AVG(email_count)) AS mean
21+
FROM inbox_stats
22+
),
23+
median AS (
24+
SELECT
25+
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY email_count) AS median
26+
FROM inbox_stats
27+
),
28+
mode AS (
29+
SELECT
30+
MODE() WITHIN GROUP (ORDER BY email_count) AS mode
31+
FROM inbox_stats
32+
)
33+
SELECT
34+
(SELECT mean FROM mean) AS mean
35+
,(SELECT median FROM median) AS median
36+
,(SELECT mode FROM mode) AS mode
37+
;
38+
```
39+
40+
## Site Solution
41+
42+
```sql
43+
-- DataLemur Solution
44+
SELECT
45+
ROUND(AVG(email_count)) as mean,
46+
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY email_count) AS median,
47+
MODE() WITHIN GROUP (ORDER BY email_count) AS mode
48+
FROM inbox_stats;
49+
```
50+
51+
## Notes
52+
53+
TODO
54+
55+
Go to [Table of Contents](/README.md#contents)\
56+
Go to [Overview](/README.md)

0 commit comments

Comments
 (0)