leetcode中行程和用户
SELECT
request_at as 'Day', round(avg(Status!='completed'), 2) as 'Cancellation Rate'
FROM
trips t JOIN users u1 ON (t.client_id = u1.users_id AND u1.banned = 'No')
JOIN users u2 ON (t.driver_id = u2.users_id AND u2.banned = 'No')
WHERE
request_at BETWEEN '2013-10-01' AND '2013-10-03'
GROUP BY
request_at
作者:luanhz
链接:https://leetcode.cn/problems/trips-and-users/solution/ci-ti-bu-nan-wei-fu-za-er-by-luanz/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
这两句中,on一方面有限定关联条件,一方面还有筛选的功能。
当inner join(即join)的时候,根本不需要on也可以,表1和表2会自动全部交叉罗列。
后面一篇讲解的更加详细
mysql中left join设置条件在on和where的区别
on后面的条件时针对右边的表(关联表),对主表没什么作用。
标签:join,users,u1,有时,mysql,筛选,u2,id From: https://www.cnblogs.com/ironan-liu/p/17288794.html