当前位置:Gxlcms > 数据库问题 > mysql查询之 用户行程的取消率,人流量高峰时段

mysql查询之 用户行程的取消率,人流量高峰时段

时间:2021-07-01 10:21:17 帮助过:2人阅读

t.Request_at Day,(round(count(if(status!="completed",status,null))/count(status),2) ) `Cancellation Rate` from Users u inner join Trips t on u.Users_id = t.Client_Id and u.banned != Yes where t.Request_at >= 2013-10-01 and t.Request_at <= 2013-10-03 group by t.Request_at

说明:

  IF(expr1,expr2,expr3)

  如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr2; 否则返回值则为 expr3。

  IF() 的返回值为数字值或字符串值

2.人流量高峰时段

每日人流量信息被记录在:序号 (id)、日期 (date)、 人流量 (people)

请编写一个查询语句,找出高峰期时段,要求连续三天及以上,并且每天人流量均不少于100。

例如,表 stadium

+------+------------+-----------+
| id   | date       | people    |
+------+------------+-----------+
| 1    | 2017-01-01 | 10        |
| 2    | 2017-01-02 | 109       |
| 3    | 2017-01-03 | 150       |
| 4    | 2017-01-04 | 99        |
| 5    | 2017-01-05 | 145       |
| 6    | 2017-01-06 | 1455      |
| 7    | 2017-01-07 | 199       |
| 8    | 2017-01-08 | 188       |
+------+------------+-----------+

对于上面的示例数据,输出为:

+------+------------+-----------+
| id   | date       | people    |
+------+------------+-----------+
| 5    | 2017-01-05 | 145       |
| 6    | 2017-01-06 | 1455      |
| 7    | 2017-01-07 | 199       |
| 8    | 2017-01-08 | 188       |
+------+------------+-----------+

Note:
每天只有一行记录,日期随着 id 的增加而增加。

select distinct s1.* from stadium s1,stadium s2,stadium s3 
where 
    s1.people>=100 and s2.people>=100 and s3.people>=100
and (
    (s1.id = s2.id-1 and s2.id=s3.id-1) or
    (s1.id = s2.id-1 and s1.id=s3.id+1) or
    (s1.id = s2.id+1 and s2.id=s3.id+1) 
) order by s1.id

 

mysql查询之 用户行程的取消率,人流量高峰时段

标签:cli   cancel   span   div   inner   保留   要求   com   not   

人气教程排行