LeetCode, SQL, 262. Trips and Users - 为什么这会给出与预期相比错误的输出?

问题描述 投票:0回答:0

我使用了 cte 和 joins,但我的输出与预期输出略有不同。 这是我的查询;

> with cte  AS 
> 
>     (SELECT id, request_at AS Day, if(status != 'completed',1,0) AS cancelled
>     FROM Trips t
>     INNER JOIN Users u
>     ON t.client_id = u.users_id OR 
>        t.driver_id = u.users_id  
>     WHERE banned = 'NO' AND 
>     (request_at BETWEEN '2013-10-01' AND '2013-10-03')
>     )
> 
> SELECT 
>     Day, 
>     ROUND(SUM(Cancelled) / COUNT(id), 2) 
      AS 'Cancellation Rate' 
      FROM cte GROUP BY Day

输出

输出: +------------+------------------+ |天 |取消率 | +------------+------------------+ | 2013-10-01 | 0.43 | | 2013-10-02 | 0.00 | | 2013-10-03 | 0.40 | +------------+-----------------+

预计 |天|取消率 | | :--------:| :----------------:| | 2013-10-01 | 0.33 | | 2013-10-02 | 0 | | 2013-10-03 | 0.5 |

有人可以解释一下我在哪里犯了错误吗?

我也尝试加入 Users 表 2 次,但这也没有用,并抛出错误。

mysql sql output inner-join rounding
© www.soinside.com 2019 - 2024. All rights reserved.