SQL每日一题(20200819)

题目

有一个商场,每日人流量信息被记录在这三列信息中:序号 (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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。