LeetCode(数据库)- 制作会话柱状图

Posted 程序员牧码

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode(数据库)- 制作会话柱状图相关的知识,希望对你有一定的参考价值。

题目链接:点击打开链接

题目大意:略。

解题思路:略。

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

以上是关于LeetCode(数据库)- 制作会话柱状图的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode:Database 97.制作会话柱状图

excel中制作柱状图的方法步骤详解

爬取房价信息并制作成柱状图

爬取房价信息并制作成柱状图

用Excel制作柱状图

在excel中,柱状图的制作方法是啥?