刷题时用到group by +case
一般来说group by 一个字段(如 name),之后其它字段不会被查询出来,但是用case when 还是能统计到其它字段的数量,很强啊~
leetcode 数据库 265题
select Request_at as "Day", round(count(case when status<>'completed' then 1 end)/count(1),2) as "Cancellation Rate" from Trips tt,Users u2,Users u1 where u2.Users_Id = tt.Client_Id and u2.banned='No' and u1.Users_Id =tt.Driver_Id and u1.banned='No' and u2.role<>'partner' and u1.role<>'partner' and tt.Request_at in ('2013-10-01','2013-10-02','2013-10-03') group by Request_at;