Skip to content

Practice Queries Quality and Percentage

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1211
LeetCode Problem

Queries Quality and Percentage

Problem Statement

Tables: Queries(query_name VARCHAR, result VARCHAR, position INT, rating INT). Queries permits duplicates. position is from 1 to 500 and rating from 1 to 5. For each query_name, return quality as the mean of rating / position across its rows, and poor_query_percentage as 100 times the fraction of rows with rating below 3. Preserve duplicate observations. Round both outputs to two decimals and return in any order.

Source: Queries Quality and Percentage on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Queries table: +------------+-------------------+----------+--------+ | query_name | result            | position | rating | +------------+-------------------+----------+--------+ | Dog        | Golden Retriever  | 1        | 5      | | Dog        | German Shepherd   | 2        | 5      | | Dog        | Mule              | 200      | 1      | | Cat        | Shirazi           | 5        | 2      | | Cat        | Siamese           | 3        | 3      | | Cat        | Sphynx            | 7        | 4      | +------------+-------------------+----------+--------+
Output
+------------+---------+-----------------------+ | query_name | quality | poor_query_percentage | +------------+---------+-----------------------+ | Dog        | 2.50    | 33.33                 | | Cat        | 0.66    | 33.33                 | +------------+---------+-----------------------+

Related LeetCode Problems

Practice more problems similar to Queries Quality and Percentage.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.