Median Search Frequency
Beginner Mode
Objective
Write a SQL query to calculate the median number of searches made by users. The table is a frequency summary where each row contains a search count and the number of users who performed that many searches. Round the result to 1 decimal place.
Table Schema:
- search_frequency
| Column | Type | Description |
|---|---|---|
| searches | INTEGER | Number of searches made |
| num_users | INTEGER | Number of users who made that many searches |
Task Requirements:
- Each row represents multiple users, not a single user
- Expand the frequency data so each user is represented individually before computing the median
- Use continuous median interpolation (average the two middle values for even-sized datasets)
- Round the result to 1 decimal place
Output columns: median_searches
Examples
Example 1:
Output:
Input:
| search_frequency | |
|---|---|
| num_users | searches |
| 2 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 5 |
| median_searches |
|---|
| 2.5 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Google