Compute Mean Rating-to-Position Quality and Poor-Result Percentage
Company: Google
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
### Problem
For each query_name, return quality and poor_query_percentage. Quality is the mean of each row’s rating/position ratio. Poor percentage is the percentage of rows with rating below 3. Round both metrics to two decimal places and allow any result row order. Duplicate input rows count.
### Tables
Table: `Queries`
```text
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| query_name | varchar |
| result | varchar |
| position | int |
| rating | int |
+-------------+---------+
This table may have duplicate rows.
This table contains information collected from some queries on a database.
The position column has a value from 1 to 500.
The rating column has a value from 1 to 5. Query with rating less than 3 is a poor query.
```
### Example
```text
Queries (query_name,result,position,rating): (alpha,A,1,4), (alpha,B,2,2), (beta,C,4,4)
Output (query_name,quality,poor_query_percentage): (alpha,2.50,50.00), (beta,1.00,0.00)
```
### What a Strong Answer Covers
- Compute each metric for all rows associated with a query name.
- Use the specified threshold and round the final metrics to two decimal places.
### Follow-up Questions
- How would you weight results from recent searches more heavily?
- How would you report separate quality metrics by search language?
Overview: Report average quality and the percentage of low-rated results for each query name.