SQL每日一题(20200819)
2020-08-19 本文已影响0人
践行数据分析
题目
有一个商场,每日人流量信息被记录在这三列信息中:序号 (id)、日期 (date)、 人流量 (people)。请编写一个查询语句,找出高峰期时段,要求连续三天及以上,并且每天人流量均不少于100。例如,表 stadium:
对于上面的示例数据,输出为:
参考:
select * into stadium1 from stadium
where people>100
select
id1=(DATEDIFF(D,'2019-01-02',date) - (select count(1) from stadium1 where date <= a.date )),
id,date,people into stadium2
from stadium1 a
select id,DATE,people
from(
select id,DATE,people,
COUNT(1) over (partition by id1) ct
from stadium2
)a
where a.ct>3