[코드카타] SQL 29 Confirmation Rate

Data_Student·2024년 11월 13일
0

코드카타

목록 보기
36/57

[코드카타] SQL 29 Confirmation Rate

29. Confirmation Rate
https://leetcode.com/problems/confirmation-rate/submissions/1451100449/

The confirmation rate of a user is the number of 'confirmed' messages 
divided by the total number of requested confirmation messages. 
The confirmation rate of a user that did not request any confirmation 
messages is 0. Round the confirmation rate to two decimal places.
Write a solution to find the confirmation rate of each user.
Return the result table in any order.
select s.user_id, round(avg(if(c.action="confirmed",1,0)),2) confirmation_rate
from Signups s left join Confirmations c on s.user_id= c.user_id 
group by user_id;
조금만 다른 관점으로 바라보면 보다 쉽게 풀이 가능!
문자로 되어있는 항목을 숫자로 변환하여 계산하기!
confirmed → 1
timeout → 0

0개의 댓글