题目描述:
你想知道用户在你的 app 上的访问时长情况。因此决定统计访问时长区间分别为 “[0-5>”, “[5-10>”, “[10-15>” 和 “15 or more” (单位:分钟)的会话数量,并以此绘制柱状图。
写一个SQL查询来报告(访问时长区间,会话总数)。结果可用任何顺序呈现。
对于 session_id 1,2 和 3 ,它们的访问时间大于等于 0 分钟且小于 5 分钟。
对于 session_id 4,它的访问时间大于等于 5 分钟且小于 10 分钟。
没有会话的访问时间大于等于 10 分钟且小于 15 分钟。
对于 session_id 5, 它的访问时间大于等于 15 分钟。
方法1:
主要思路:
select '[0-5>' as bin,count(*) as total from Sessions where duration/60 >=0 and duration/60<5
union select '[5-10>' as bin,count(*) as total from Sessions where duration/60 >=5 and duration/60<10
union select '[10-15>' as bin,count(*) as total from Sessions where duration/60 >=10 and duration/60<15
union select '15 or more' as bin,count(*) as total from Sessions where duration/60 >=15