AnalystPath

Median Reading From a Frequency Table

SQLHardSenior level~15 min

Problem

Table: `Reading`

```text
+-----------+------+
| Column | Type |
+-----------+------+
| value | int |
| occurs | int |
+-----------+------+
value is the primary key. `occurs` is how many times that value was recorded by a sensor.
```

If you expanded the table so each `value` appeared `occurs` times, what would the **median** of the whole expanded list be? Report it rounded to **one decimal place** and label the column `median`.

**Example**

```text
Reading:
+-------+--------+
| value | occurs |
+-------+--------+
| 0 | 7 |
| 1 | 1 |
+-------+--------+

Output:
+--------+
| median |
+--------+
| 0.0 |
+--------+
```

Expanded, the list is seven 0s and one 1 (eight values); the median is the average of the 4th and 5th values, both 0, so 0.0.

Tables

Example rows — the live problem includes the full dataset.

Reading
valueoccurs
07
11

Expected output

Your answer should return 1 row with the columns median.

Starter code (SQL)

SELECT *
FROM Reading;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions