The Calculate Compressed Mean interview question is a SQL/Database task centered on data aggregation. You are given a table where rows represent "compressed" data—for example, a row might state that there were 5 orders of 10 items each. Your goal is to calculate the overall average (mean) of the items across all orders. This Calculate Compressed Mean coding problem tests your ability to handle frequency-weighted averages in a relational database.
Google and other data-driven companies use this to evaluate a candidate's proficiency with SQL aggregate functions. It checks if you understand how to perform arithmetic within a SELECT statement and how to correctly use SUM() to handle weighted values. It’s a practical test of data manipulation skills often needed in analytics and reporting.
This follows the Database interview pattern. The "Mean" is calculated as the (Total Sum of Items) / (Total Number of Orders).
Suppose you have a table Orders:
Always look for "frequency" or "count" columns in database problems. If they exist, your aggregate calculations (like mean or median) must be weighted by those values. Practice using SUM(colA * colB) for weighted totals.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Calculate Special Bonus | Easy | Solve | |
| Find Customers With Positive Revenue this Year | Easy | Solve | |
| Find Expensive Cities | Easy | Solve | |
| Loan Types | Easy | Solve | |
| The Latest Login in 2020 | Easy | Solve |