Trips and Users

The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table. Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).
±—±----------±----------±--------±-------------------±---------+
| Id | Client_Id | Driver_Id | City_Id | Status |Request_at|
±—±----------±----------±--------±-------------------±---------+
| 1 | 1 | 10 | 1 | completed |2013-10-01|
| 2 | 2 | 11 | 1 | cancelled_by_driver|2013-10-01|
| 3 | 3 | 12 | 6 | completed |2013-10-01|
| 4 | 4 | 13 | 6 | cancelled_by_client|2013-10-01|
| 5 | 1 | 10 | 1 | completed |2013-10-02|
| 6 | 2 | 11 | 6 | completed |2013-10-02|
| 7 | 3 | 12 | 6 | completed |2013-10-02|
| 8 | 2 | 12 | 12 | completed |2013-10-03|
| 9 | 3 | 10 | 12 | completed |2013-10-03|
| 10 | 4 | 13 | 12 | cancelled_by_driver|2013-10-03|
±—±----------±----------±--------±-------------------±---------+
The Users table holds all users. Each user has an unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).
±---------±-------±-------+
| Users_Id | Banned | Role |
±---------±-------±-------+
| 1 | No | client |
| 2 | Yes | client |
| 3 | No | client |
| 4 | No | client |
| 10 | No | driver |
| 11 | No | driver |
| 12 | No | driver |
| 13 | No | driver |
±---------±-------±-------+
Write a SQL query to find the cancellation rate of requests made by unbanned users between Oct 1, 2013 and Oct 3, 2013. For the above tables, your SQL query should return the following rows with the cancellation rate being rounded to two decimal places.

Example

±-----------±------------------+
| Day | Cancellation Rate |
±-----------±------------------+
| 2013-10-01 | 0.33 |
| 2013-10-02 | 0.00 |
| 2013-10-03 | 0.50 |
±-----------±------------------+

Solution

# Write your MySQL query statement below
SELECT T.Request_at AS Day, ROUND(SUM(CASE WHENT.Status LIKE "cancelled%" THEN 1ELSE 0END)/COUNT(*), 2) AS "Cancellation Rate"FROM Trips TLEFT JOIN Users U ON T.Client_Id = U.Users_IdWHERE U.Banned="No" And T.Request_at Between '2013-10-01' AND '2013-10-03'GROUP BY T.request_atORDER BY T.request_at

Trips and Users相关推荐

  1. [Manthan, Codefest 18][Codeforces 1037E. Trips]

    题目链接:1037E - Trips 题目大意:有n个人,m天,每天晚上都会有一次聚会,一个人会参加一场聚会当且仅当聚会里有至少k个人是他的朋友.每天早上都会有一对人成为好朋友,问每天晚上最多能有多少 ...

  2. LeetCode Trips and Users(关联、分组,聚合)

    给出trips和users表 CREATE TABLE `trips` (   `Id` int(11) DEFAULT NULL,   `Client_Id` int(11) DEFAULT NUL ...

  3. Codechef TRIPS Children Trips (分块、倍增)

    题目链接: https://www.codechef.com/problems/TRIPS 感觉CC有点毒瘤啊.. 题解: 首先有一个性质可能是因为太傻所以网上没人解释,然而我看了半天: 就是正序和倒 ...

  4. 一二三系列之CodeChef分块——Chef and Churu,Chef and Problems,Children Trips

    文章目录 Chef and Churu source solution code Chef and Problems source solution code Children Trips sourc ...

  5. [CodeChef Trips]Children Trips

    Children Trips 题解 关于这种跳跃的**题,当它PPP值很大时几次就可以跳到目标节点了,而较小时却会跳很久,所以我们很快就可以想到对询问分类处理. 对于P>nP>\sqrt{ ...

  6. Codeforces - Trips

    题目链接:Codeforces - Trips 加边不好想,所以我们直接反向删边. 每次删除一条边,那么对应两个点的度都减1,每次都把度小于k的删掉,剩下的点就是答案. 删点直接标记即可,删边在set ...

  7. [CC-TRIPS]Children Trips

    [CC-TRIPS]Children Trips 题目大意: \(n(n\le10^5)\)座城市构成一棵树,且树上的每条边的长度\(l_i\)满足\(1\le l_i\le 2\).\(m(m\le ...

  8. 262. Trips and Users

    The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are b ...

  9. 出租权不适用于计算机软件,TRIPS协议下我国软件产业知识产权保护问题研究

    [摘要] TRIPS协议中有关软件知识产权保护的内容是国际软件保护适用最广泛的规则.我国现行相关法律与TRIPS协议在相关权利上.某些权利保护方式以及保护水平上还没有实现充分对接,需要进步修订以适应T ...

最新文章

  1. Flutter 导包 以及体验
  2. WPF入门:数据绑定
  3. bootstrapTable语言包设置
  4. c#中的非托管资源释放 (Finalize和Dispose)
  5. 数组名的地址,和数组名取地址的讨论
  6. 我学习Python的三个神级网站
  7. word椭圆形标注怎么设置_轻松应对毕业季,搞定论文图表,word中处理原来没你想象的那么难...
  8. Linux下的I/O复用与epoll详解(ET与LT)
  9. 算法与数据结构1800题 之 栈和队列
  10. [bzoj4278][ONTAK2015]Tasowanie_后缀数组_贪心
  11. C#读取网络流,读取网络上的js文件
  12. WPF Summary:XAML的介绍
  13. java for语句_Java for循环语句
  14. Kubernetes CKA认证运维工程师笔记-Kubernetes存储
  15. java修改文件后缀_java批量修改文件后缀的方法介绍
  16. C#编程,获取当前时间为一年的第几周的一种方法。
  17. VSC 最新版本 加入实用功能Pinned
  18. 详解:化工厂人员定位方案与双重预防机制建设
  19. 云计算机lol,云电脑玩英雄联盟卡不卡?
  20. 我的第一次知识图谱问答

热门文章

  1. Python(十一) 原生爬虫
  2. JNPF快速开发框架的八大功能介绍
  3. 2022电动两轮市场格局分化,九号异军突起
  4. 模拟【CSP201609-3炉石传说】
  5. 18天精读掌握《费曼物理学讲义卷一》 第8天 2019.6.21
  6. linux 命令行 mpv,在Ubuntu本机编译mpv,秒杀其他播放器
  7. 怎样传文件到虚拟服务器,Vmware虚拟机教程之本机如何传文件到VMware 中
  8. 关于vmware(CENTOS 7 )虚拟机NAT模式下连不上网的问题解决。
  9. 基于部分卷积Pconv的图片修复
  10. 1011: 圆柱体表面积 Java