SQL
All Top 50 SQL Interview Questions#25
Search Query Quality and Poor Query Percentage in SQL
MediumGoogleInterview Question #25
Asked at GoogleGiven a `queries` table (query_name, result, position, rating), calculate `quality` as the average of `(rating / position)` and `poor_query_percentage` as the percentage of queries with rating < 3. Round both to 2 decimal places.
Input Table: queries
4 rows preview| query_name | position | rating |
|---|---|---|
| Dog | 1 | 5 |
| Dog | 2 | 5 |
| Dog | 200 | 1 |
| Cat | 1 | 5 |
Expected Output Structure2 rows
| query_name | quality | poor_query_percentage |
|---|---|---|
| Dog | 2.5 | 33.33 |
| Cat | 5 | 0 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.