262. Trips and Users
https://leetcode.com/problems/trips-and-users/
Trips and Users - LeetCode
Can you solve this real interview question? Trips and Users - Table: Trips +-------------+----------+ | Column Name | Type | +-------------+----------+ | id | int | | client_id | int | | driver_id | int | | city_id | int | | status | enum | | request_at |
leetcode.com
The cancellation rate is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day.
Write a SQL query to find the cancellation rate of requests with unbanned users (both client and driver must not be banned) each day between "2013-10-01" and "2013-10-03". Round Cancellation Rate to two decimal points.
취소 비율은 '해당 날짜에 차단되지 않은 사용자가 있는 취소된(클라이언트 또는 드라이버에 의한) 요청 수'를
'금지되지 않은 사용자가 있는 총 요청 수'로 나누어 계산합니다.
매일 "2013-10-01"과 "2013-10-03" 사이에 금지되지 않은 사용자(클라이언트와 드라이버 모두 금지되지 않아야 함)가 있는 요청의 취소 비율을 찾기 위해 SQL 쿼리를 작성하십시오.
라운드 취소 비율은 소수점 둘째 자리입니다.
정답 코드
SELECT request_at AS Day
, ROUND((SUM(CASE WHEN status != 'completed' THEN 1 ELSE 0 END)
/ COUNT(DISTINCT id)),2) AS 'Cancellation Rate'
FROM Trips
WHERE request_at BETWEEN "2013-10-01" AND "2013-10-03"
AND client_id NOT IN (SELECT users_id
FROM Users
WHERE banned = "Yes")
AND driver_id NOT IN (SELECT users_id
FROM Users
WHERE banned = "Yes")
GROUP BY request_at;
'🛠️Skill > CodingTest' 카테고리의 다른 글
[leetcode] 601. Human Traffic of Stadium / 연속된 숫자 3개 이상 (0) | 2023.04.19 |
---|---|
[leetcode] 1321. Restaurant Growth/7일간의 이동 평균 (0) | 2023.03.29 |
[leetcode] 1341. Movie Rating / 평점 가장 많이 남긴 사람, 평점이 가장 높은 영화 (0) | 2023.03.27 |
[leetcode] 1204. Last Person to Fit in the Bus / 버스 마지막 승객 구하기 (0) | 2023.03.09 |
[leetcode] 1174. Immediate Food Delivery II / 즉시배송할 수 있는 주문비율 (0) | 2023.03.08 |
댓글