LeetCode 262. Trips and Users
来源:互联网 发布:融资租赁数据 编辑:程序博客网 时间:2024/05/19 05:02
select allo.r, round(ifnull(canceled.c/allo.c,0),2) from(select count(1) as c,Request_at as r from Trips t,Users u where t.Client_Id = u.Users_Id and u.Banned = 'No' and t.Request_at between '2013-10-01' and '2013-10-03' and t.Status != 'completed' group by Request_at) canceled right join (select count(1) as c,Request_at as r from Trips t,Users u where t.Client_Id = u.Users_Id and u.Banned = 'No' and t.Request_at between '2013-10-01' and '2013-10-03' group by Request_at) allo on canceled.r = allo.r
需要注意的是:
- Leetcode的sql是认大小写的
- as 后面的重命名字符串如果有空格需要用单引号圈起来,如’ Cancellation Rate ‘
- 表名列名不能重命名成all
- 答案中需要保留两位
附上数据库脚本:
+----+-----------+-----------+---------+--------------------+----------+| 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|+----+-----------+-----------+---------+--------------------+----------+create table Trip ( Id Integer Primary Key, Client_Id Integer, Driver_Id Integer, City_Id Integer, Status varchar(255), Request_at DATE);+----------+--------+--------+| 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 |+----------+--------+--------+create table Users ( Users_Id Integer Primary Key, Banned varchar(255), Role varchar(255));
0 0
- LeetCode 262. Trips and Users
- leetcode 262. Trips and Users
- [LeetCode]--262. Trips and Users
- [leetcode]Trips and Users
- leetcode-database-262. Trips and Users
- 【leetcode Database】262. Trips and Users
- [Leetcode] [Database] Trips and Users解题思路
- Trips and Users --Hard
- LeetCode_OJ【262】Trips and Users
- Trips and Users ---刷完database 留念
- Users and Groups----note
- SYS and SYSTEM Users
- SQL Server Logins and Users - Orphaned Users
- Linux for Programmers and Users
- Users and Groups in Linux
- Difference for Logins and Users
- Main Users and the pwd
- Oracle Default Users And Password
- Prototype Pattern
- Builder
- scala参数是个函数
- Android Studio配置 二
- 树莓派搭建股票量化分析服务器 基于tushare python
- LeetCode 262. Trips and Users
- Android Studio配置 一
- Express.js路由详解
- Android Studio配置三 gradle项目构建
- Java的异常类
- Android之TextView
- 程序员的十个经典算法
- hdu 3336 Count the string
- linux 修改启动脚本导致的错误:not a valid identifier