Leetcode- 262. Trips and Users(틀림)

르네·2023년 11월 20일
0

SQL

목록 보기
58/63

문제

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 solution 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.

Return the result table in any order.

The result format is in the following example.

풀이

WITH ban AS (
  SELECT users_id
  FROM users
  WHERE banned = 'No'
)

SELECT request_at AS Day
     , ROUND(SUM(CASE WHEN status LIKE 'cancelled%' THEN 1 ELSE 0 END) / COUNT(*), 2) AS 'Cancellation Rate'
FROM trips
WHERE client_id IN (SELECT users_id from ban)
  AND driver_id IN (SELECT users_id from ban)
  AND request_at BETWEEN '2013-10-01' AND '2013-10-03'
GROUP BY request_at

배운점

  • ALIAS 뒤에 공백이나 특수문자가 들어가면 따옴표로 감싸줘야 한다.
profile
데이터분석 공부로그

0개의 댓글

Powered by GraphCDN, the GraphQL CDN