[LeetCode/SQL50] Confirmation rate
2025. 7. 7. 10:09ㆍ개인활동/코테
반응형
/* Write your T-SQL query statement below */
select S.user_id,
round(isnull(sum(case when action = 'confirmed' then 1 end)*1.00/count(*),0),2) as confirmation_rate
from Signups as S
left join Confirmations as C on S.user_id = C.user_id
group by S.user_id;
- Left join 사유: right join을 하는 경우 id 6이 누락됨
- isnull을 통해 null값을 가진 경우 자동으로 rate 0을 반환하도록 함
- id를 기준으로 groupby를 함으로써 각 아이디별 confirmed 비율을 구할 수 있도록 함
- case절
- Case when ~~상황에서 then ~~한 결과를 내보냄 End
- Case로 조건절 열어주고 End로 닫아줌
반응형
'개인활동 > 코테' 카테고리의 다른 글
[30 Days of JS] Interval Cancellation / Promise Time Limit (0) | 2025.05.18 |
---|---|
[30 Days of JS] Sleep / Timeout Cancellation (0) | 2025.05.15 |
[30 Days of JS] Memoize / Add two promises (1) | 2025.05.14 |
[30 Days of JS] Return length of arguments passed / (0) | 2025.05.11 |
[30 Days of JS] Array reduce transformation / Function composition (0) | 2025.05.10 |