Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-1809.test 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
# $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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助