【SQL】LeetCode-Trips and Users

此SQL查询旨在确定2013年10月1日至3日期间,由未被禁用的用户(客户端和驾驶员)发起的请求中,被取消的请求所占的比率。通过将被取消的请求数量除以所有未被禁用用户的总请求数,计算出取消率。结果按日期分组并四舍五入到小数点后两位。
摘要由CSDN通过智能技术生成

LeetCode 262:Trips and Users

【Description】

在这里插入图片描述在这里插入图片描述
Write a SQL query to find the cancellation rate of requests made by unbanned users (both client and driver must be unbanned) between “2013-10-01” and “2013-10-03”.

The cancellation rate is computed by dividing the number of canceled (by client or driver) requests made by unbanned users by the total number of requests made by unbanned users.

Return the result table in any order. Round Cancellation Rate to two decimal points.

The query result format is in the following example:
在这里插入图片描述
在这里插入图片描述

【Solution】

Personal solution:

with temp as (
    select *
    from trips
    where client_id not in (select users_id from users where banned = "yes")
    and request_at between "2013-10-01" and "2013-10-03"
)
select request_at as "Day",
       round(sum(if (status like "cancelled_by_%",1,0))/count(1),2) as "Cancellation Rate"
from temp
group by request_at

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值