Tags
- M:N
- Article & User
- update
- SQL
- 큐
- create
- 이진트리
- delete
- N:1
- regexp
- DB
- stack
- 쟝고
- 완전검색
- 통계학
- migrations
- 그리디
- 백트래킹
- 스택
- 뷰
- outer join
- distinct
- ORM
- drf
- count
- 트리
- Vue
- Django
- Tree
- Queue
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Notice
Recent Posts
Link
데이터 분석 기술 블로그
Confirmation Rate _ Medium. LeetCode 본문



SELECT s.user_id,
ROUND(IFNULL(SUM(CASE WHEN c.action = 'confirmed' THEN 1 ELSE 0 END) / COUNT(c.user_id), 0), 2) AS confirmation_rate
FROM Signups s
LEFT JOIN Confirmations c
ON s.user_id = c.user_id
GROUP BY s.user_id;
- JOIN을 사용하지 않으면 Signups에 있는 user_id가 반영이 안 된다.
- IFNULL을 사용해서 NULL일 때 0이라는 조건을 넣지 않으면 Confirmations 테이블에 없는 user_id에는 confirmation_rate가 NULL로 나타난다. 우리는 0이 필요하므로 IFNULL을 사용했다.
'SQL > 문제풀이' 카테고리의 다른 글
| Find Users With Valid E-Mails _ Easy. LeetCode (0) | 2025.01.09 |
|---|---|
| Last Person to Fit in the Bus _ Medium. LeetCode (0) | 2025.01.08 |
| Customers Who Bought All Products _ Medium.LeetCode * (0) | 2025.01.06 |
| Consecutive Numbers _ Medium.LeetCode (0) | 2025.01.05 |
| Product Sales Analysis III _ Medium. LeetCode (0) | 2025.01.04 |