Fork me on GitHub

SQL 分组后进行相关统计

求每位同学考试成绩90分以上的优秀率

 SELECT student_id,ROUND(AVG(score>90),2)
 FROM `score`
 GROUP BY `student_id`

求每日的乘客取消率

select t.Request_at as `Day`,
(
    round(avg(Status!='completed'),2)
) as `Cancellation Rate`
from
    Users u inner join Trips t
on
    u.Users_id = t.Client_Id
where u.Banned='No'
and t.Request_at >='2013-10-01'
and t.Request_at <='2013-10-03'
group by t.Request_at
posted @ 2020-08-19 14:10  园狐  阅读(1027)  评论(0编辑  收藏  举报