【发布时间】:2021-04-25 02:20:05
【问题描述】:
我想了解以下查询背后的连接逻辑?? 下面是正在使用的表格
on t1.log_id-1 = t2.log_id
where t2.log_id is null
完整查询:-
select start_id, min(end_id) as end_id
from (
select t1.log_id as start_id
from logs as t1
left join logs as t2
on t1.log_id-1 = t2.log_id
where t2.log_id is null
) tt_start
join (
select t1.log_id as end_id
from logs as t1
left join logs as t2
on t1.log_id+1 = t2.log_id
where t2.log_id is null
) tt_end
where start_id<=end_id
group by start_id
表:-
Log_id
1
2
3
7
8
10
【问题讨论】:
-
请格式化您的 SQL,使其更具可读性。
-
你的问题到底是什么?
-
这能回答你的问题吗? How to Join to first row
-
@RakshaSaini 几乎完全不相关。这是一个不存在的语法,不是顶级 1
-
请始终使用您正在使用的 DBMS 标记 SQL 请求。这可能非常重要,因为 SQL 方言有时会有很大差异。
标签: sql left-join not-exists