본문 바로가기
SQL/LeetCode

[LeetCode][SQL50] #19. Queries Quality and Percentage

by 이뮴 2023. 11. 15.
728x90

💻 문제 주소 : Percentage of Users Attended a Contest - LeetCode

 

Percentage of Users Attended a Contest - LeetCode

Can you solve this real interview question? Percentage of Users Attended a Contest - Table: Users +-------------+---------+ | Column Name | Type | +-------------+---------+ | user_id | int | | user_name | varchar | +-------------+---------+ user_id is the

leetcode.com

 

💻 문제

Write a solution to find each query_name, the quality and poor_query_percentage. Both quality_and poor_query_percentage should be rounded to 2 decimal places. Return the result table in any order.

* quality : The average of the ratio between query rating and its position

* poor_query_percentage : The percentage of all queries with rating less than 3

- 각 동물별 quality와 poor_query_percentage를 구하시오. quality는 query rating과 position의 평균이며, poor_query_percentage는 rating이 3 미만인 모든 query의 비율을 의미합니다. 이 비율 모두 소수점 두 자리까지 출력되어야 하며, 결과 테이블 순서는 상관 없습니다. 

 

💻 코드 및 풀이 

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
 
728x90
반응형