Median Search Frequency
Google 🧠 Hard SQL
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:

Input:

search_frequency
num_userssearches
21
12
13
25

Output:
median_searches
2.5
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →