栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

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

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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/279956.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号