每一题-93(制作会话柱状图)

题93:

根据下表写一个SQL查询来报告(访问时长区间,会话总数),结果可用任何顺序呈现。
其中:决定统计访问时长区间分别为 “[0-5>”, “[5-10>”, “[10-15>” 和 “15 or more” (单位:分钟)的会话数量,并以此绘制柱状图。
在这里插入图片描述
其中:session_id 是该表主键,duration 是用户访问应用的时间, 以秒为单位。

解题思路:用union将每个区间连接,统计每个区间的个数即可。

select '[0-5>'  bin,count(duration)  total
from Sessions
where duration < 300
union
select '[5-10>'  bin,count(duration)  total
from Sessions
where duration >= 300 and duration < 600
union
select '[10-15>'  bin,count(duration)  total
from Sessions
where duration >= 600 and duration < 900
union
select '15 or more'  bin,count(duration)  total
from Sessions
where duration > 900;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值