๐ป ๋ฌธ์ ์ฃผ์ : Confirmation Rate - LeetCode
Confirmation Rate - LeetCode
Can you solve this real interview question? Confirmation Rate - Table: Signups +----------------+----------+ | Column Name | Type | +----------------+----------+ | user_id | int | | time_stamp | datetime | +----------------+----------+ user_id is the colum
leetcode.com
๐ป ๋ฌธ์
Write a solution to find the confirmation rate of each user. Return the table in any order.
* Confirmation rate : the number of 'confirmed' messgaes divided by the total number of requested confirmation messgaes. The rate that did not request any confirmation messages is 0. Round the confirmation rate to two decimal places.
- ๊ฐ ์ ์ ์ confirmation rate๋ฅผ ๊ตฌํ์์ค. ์ด๋ confirmation rate๋, ์ ์ฒด ์๋ต ๋ฉ์์ง ์ค confirmed ๋ฉ์์ง๊ฐ ์ฐจ์งํ๋ ๋น์จ์ ๋งํ๋ ๊ฒ์ผ๋ก, ์๋ฌด๋ฐ ์๋ต์ ํ์ง ์์ ๊ฒฝ์ฐ 0์ผ๋ก ์ธก์ ํฉ๋๋ค. confirmation rate๋ ์์์ ๋ ์๋ฆฌ๊น์ง ์ถ๋ ฅํ๋ฉฐ, ์ถ๋ ฅ ํ ์ด๋ธ์ ์์๋ ์๊ด ์์ต๋๋ค.
๐ป ์ฝ๋ ๋ฐ ํ์ด
select s.user_id, round(avg(if(c.action = 'confirmed', 1, 0)), 2) as confirmation_rate
from Signups s
left join Confirmations c on s.user_id = c.user_id
group by user_id
'SQL > LeetCode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode][SQL50] #16. Average Selling Price (0) | 2023.11.14 |
---|---|
[LeetCode][SQL50] #15. Not Boring Movies (2) | 2023.11.13 |
[LeetCode][SQL50] #13. Managers with at Least 5 Direct Reports (0) | 2023.11.09 |
[LeetCode][SQL50] #12. Students and Examinations (0) | 2023.11.09 |
[LeetCode][SQL50] #11. Employee Bonus (0) | 2023.11.08 |