DB2 database queries qualified data in adjacent data (time adjacent)

question: query all data whose RUN_TYPE is 1 and SWITCH_TYPE is 1 in adjacent time (RUN_DATE) of ID.

data sheet: Tunable data, as shown in the figure.

clipboard.png

:RUN_TYPE1SWITCH_TYPE1IDRUN_DATE

SQL:SELECT * FROM T_DATA a WHERE a.SWITCH_TYPEIN("1") AND (a.RUN_TYPE) IN
("1") ORDER BY ID , RUN_DATE
:

:
clipboard.png

unresolved: the query result with an ID of 4 does not meet the requirements, and the two pieces of data do not meet the conditions of contiguous RUN_DATE (there is a RUN_TYPE of 0 in the middle).

question: how to compare adjacency (adjacent time) in SQL?

Nov.22,2021
Menu