代码拉取完成,页面将自动刷新
# $1809. 没有广告的剧集
# https://leetcode.cn/problems/ad-free-sessions/
# SQL架构
Create table If Not Exists Playback(session_id int,customer_id int,start_time int,end_time int);
Create table If Not Exists Ads (ad_id int, customer_id int, timestamp int);
Truncate table Playback;
insert into Playback (session_id, customer_id, start_time, end_time) values ('1', '1', '1', '5');
insert into Playback (session_id, customer_id, start_time, end_time) values ('2', '1', '15', '23');
insert into Playback (session_id, customer_id, start_time, end_time) values ('3', '2', '10', '12');
insert into Playback (session_id, customer_id, start_time, end_time) values ('4', '2', '17', '28');
insert into Playback (session_id, customer_id, start_time, end_time) values ('5', '2', '2', '8');
Truncate table Ads;
insert into Ads (ad_id, customer_id, timestamp) values ('1', '1', '5');
insert into Ads (ad_id, customer_id, timestamp) values ('2', '2', '17');
insert into Ads (ad_id, customer_id, timestamp) values ('3', '2', '20');
# Write your MySQL query statement below
select
session_id
from
Playback
where
session_id not in (
select
distinct(p.session_id)
from
Playback p
left join Ads a on p.customer_id = a.customer_id
where
p.start_time <= a.timestamp
and a.timestamp <= p.end_time
);
# clean-up
drop table Playback;
drop table Ads;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。