I have a table in which all the records have an id, timestamp, and a Boolean value. I need to discover in which records the Boolean changes to false within 1 second of it being true for the same id.
I’ve been working on the following statement, but after doing some research, I feel either a CASE combined with a FETCH statement might work better, but I haven’t found a good example where they’ve been used together.
SELECT *
FROM Table_1
WHERE timestamp IN(
SELECT DATEADD(Second, 1, timestamp)
from Table_1
where Boolean = 1)
AND ID in (
SELECT ID
from Table_1 where Boolean = 1)
AND Boolean = 0
How about:
a matter of taste as to how much of that you put in the join clause and how much you put into a where clause.
Edits