#93. [LeetCode / MySQL] 1211. Queries Quality and Percentage

문제

 

입력 코드

1. IF

SELECT 
    query_name,
    ROUND(AVG(rating/position), 2) AS quality,
    ROUND(AVG(IF(rating < 3, 1, 0))*100, 2) AS poor_query_percentage
FROM Queries
GROUP BY query_name

 

2. CASE WHEN

SELECT 
    query_name,
    ROUND(AVG(rating/position), 2) AS quality,
    ROUND(SUM(
                CASE WHEN rating < 3 THEN 1 
                ELSE 0 
                END
                ) * 100 / COUNT(*), 2) AS poor_query_percentage
FROM Queries
GROUP BY query_name

 

코드 설명

#SELECT #ROUND #AVG #IF #GROUP BY #SUM #CASE WHEN #COUNT 

 

 

문제 출처

 

Queries Quality and Percentage - LeetCode

Can you solve this real interview question? Queries Quality and Percentage - Table: Queries +-------------+---------+ | Column Name | Type | +-------------+---------+ | query_name | varchar | | result | varchar | | position | int | | rating | int | +------

leetcode.com