首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >LeetCode.601.Human_Traffic_of_Stadium

LeetCode.601.Human_Traffic_of_Stadium

作者头像
大数据工程师-公子
发布2019-06-15 15:18:23
发布2019-06-15 15:18:23
42400
代码可运行
举报
运行总次数:0
代码可运行

Creative Commons

601.Human_Traffic_of_Stadium

https://leetcode.com/problems/human-traffic-of-stadium/

Solution-for-3_or_more consecutive_visit_date

代码语言:javascript
代码运行次数:0
运行
复制
Create table temp_visit_date
 select
	b.id,
	b.visit_date,
	b.people,
	DATE_SUB(visit_date,INTERVAL b.rk DAY) as diffdate
from (
	select
	a.id, 
	a.visit_date, 
	a.people, 
	(select count(distinct visit_date) from stadium b where b.people >= 100 and b.visit_date <= a.visit_date) as rk
	from stadium a 
	where a.people >= 100
	order by visit_date ASC
) b;

select
id,
visit_date,
people
from (
	select diffdate, count(1) as cnt from temp_visit_date group by diffdate having cnt >= 3
)tt left join temp_visit_date aa on aa.diffdate = tt.diffdate
;

Solutionp-for-3_or_more consecutive_rows

代码语言:javascript
代码运行次数:0
运行
复制
# Write your MySQL query statement below
select
    zz.id,
    zz.visit_date,
    zz.people
from (
    select diff_row, count(1) as cnt from (
        select
        b.id,
        b.visit_date,
        b.people,
        (id-rk) as diff_row
    from (
        select
            a.id, 
            a.visit_date, 
            a.people, 
            (select count(distinct id) from stadium b where b.people >= 100 and b.id <= a.id) as rk
        from stadium a 
        where a.people >= 100
        order by id ASC
    ) b
    ) xx group by diff_row having cnt >= 3
) tt left join (
    select
        b.id,
        b.visit_date,
        b.people,
        (id-rk) as diff_row
    from (
        select
            a.id, 
            a.visit_date, 
            a.people, 
            (select count(distinct id) from stadium b where b.people >= 100 and b.id <= a.id) as rk
        from stadium a 
        where a.people >= 100
        order by id ASC
    ) b
) zz on zz.diff_row = tt.diff_row
;
代码语言:javascript
代码运行次数:0
运行
复制
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年06月13日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 601.Human_Traffic_of_Stadium
    • Solution-for-3_or_more consecutive_visit_date
    • Solutionp-for-3_or_more consecutive_rows
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档