In the data below Event1 represents the end of a manufacturing cycle. Event2 happens during on a percentage of the cycles. I was wondering if it is possible to pull the end of cycle time (when Event1 returns to 0) and the maximum value of Event2 (either 0 or 1) during that cycle. Both values are binary.
DateTime Event1 Event2
12/5/2012 07:00 1 0
12/5/2012 07:01 0 0
12/5/2012 07:45 1 0
12/5/2012 07:46 0 0
12/5/2012 07:50 0 1
12/5/2012 07:54 0 0
12/5/2012 08:30 1 0
12/5/2012 08:31 0 0
DateTime max(Event2)
12/5/2012 07:46 0
12/5/2012 08:31 1
I'm using WonderWare historian database, so there are some unique options in the query. Below is what I use to find the end of cycle times.
SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime
FROM WideHistory
WHERE wwRetrievalMode = 'Delta'
AND Event1 = 1
AND wwEdgeDetection = 'TRAILING'
AND wwVersion = 'Latest'
AND DateTime >= '20121205 07:00'
AND DateTime <= '20121205 09:00'")
Is there a way to use the results of this query to generate DateTime restrictions of additional queries?