来自初学者的问题.
我有两张桌子.一个(A)包含Start_time, End_time, Status.第二个(B)包含Timestamp, Error_code.系统每隔几秒自动记录第二个表,因此它包含许多非唯一的Error_code值(它随机变化,但在表A的时间范围内).我需要的是为表A中的每个时间范围的第一个表中的每个时间范围(在我的情况下每一行)选择唯一的错误代码:
A.Start_time,A.End_time B.Error_code.
我来过这个:
select A.Start_time,
A.End_time,
B.Error_code
from B
inner join A
on B.Timestamp between A.Start_time and A.End_time
Run Code Online (Sandbox Code Playgroud)
我知道这是错的.欢迎任何想法.
如果游览查询提供了大量重复项,请使用distinct来删除它们:
select DISTINCT A.Start_time, A.End_time, B.Error_code
from B
inner join A on B.Timestamp between A.Start_time and A.End_time
Run Code Online (Sandbox Code Playgroud)