Queries Quality and Percentage
Preview mode. Log in to edit, run, submit, and save progress.
Queries Quality and Percentage
You have a Queries table. Each row represents a search query result with a position and a rating. Define: - quality: the average of (rating / position) for each query_name, rounded to 2 decimal places. - poor_query_percentage: the percentage of results with rating < 3 for each query_name, rounded to 2 decimal places. Write a SQL query to report the query_name, quality, and poor_query_percentage for each query. Return the result in any order.
Examples
Dog quality = ((5/1)+(5/2)+(1/200))/3 = 2.50. Dog poor% = 1/3 * 100 = 33.33. Cat quality = ((2/5)+(3/3)+(4/7))/3 = 0.66. Cat poor% = 1/3 * 100 = 33.33.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.