题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1) WITH t1 AS(SELECT '[0-5>' bin UNION ALL SELECT '[5-10>' bin UNION ALL SELECT '[10-15>' bin UNION ALL SELECT '15 or more' bin), t2 AS(SELECT CASE WHEN duration BETWEEN 0 AND 299 THEN '[0-5>' WHEN duration BETWEEN 300 AND 599 THEN '[5-10>' WHEN duration BETWEEN 600 AND 899 THEN '[10-15>' ELSE '15 or more' END bin FROM Sessions), t3 AS(SELECT bin, COUNT(*) total FROM t2 GROUP BY bin) SELECT t1.bin, IFNULL(total, 0) total FROM t1 LEFT JOIN t3 ON t3.bin = t1.bin -- 解决方案(2) 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