๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SQL/LeetCode

[LeetCode][SQL50] #14. Confirmation Rate

by ์ด๋ฎด 2023. 11. 13.
728x90

๐Ÿ’ป ๋ฌธ์ œ ์ฃผ์†Œ : 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
728x90
๋ฐ˜์‘ํ˜•

'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