💻 문제 주소 : 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
'SQL > LeetCode' 카테고리의 다른 글
[LeetCode][SQL50] #21. Immediate Food Delivery II (1) | 2024.01.01 |
---|---|
[LeetCode][SQL50] #20. Monthly Transactions I (0) | 2023.11.16 |
[LeetCode][SQL50] #18. Percentage of Users Attended a Contest (0) | 2023.11.15 |
[LeetCode][SQL50] #17. Project Employees I (0) | 2023.11.15 |
[LeetCode][SQL50] #16. Average Selling Price (0) | 2023.11.14 |