当前位置:Gxlcms > 数据库问题 > 【leetcode database】Human Traffic of Stadium

【leetcode database】Human Traffic of Stadium

时间:2021-07-01 10:21:17 帮助过:23人阅读

这题的难度属于hard级别,但我觉得最多也就是一般难度。初看起来这题好像有点不知所措,但仔细分析却能发现其实条件很简单,只要满足以下任意三个条件即可:

1.id in (x,x+1,x+2) 的记录的people >= 100;

2.1.id in (x,x+1,x-1) 的记录的people >= 100;

3.1.id in (x,x-1,x-2) 的记录的people >= 100;

代码如下:

select * from stadium a   where a.people >= 100 and 
(
(
a.id+1 in  (select id from stadium where people >= 100) 
and 
a.id+2 in  (select id from stadium where people >= 100) 
)
or 
(
a.id-1  in  (select id from stadium where people >= 100) 
and 
a.id+1  in  (select id from stadium where people >= 100) 
)
or 
(
a.id-1  in  (select id from stadium where people >= 100) 
and 
a.id-2  in  (select id from stadium where people >= 100) 
)
);

 

【leetcode database】Human Traffic of Stadium

标签:分析   stat   uil   incr   lease   rds   city   nbsp   which   

人气教程排行