I’d like to get a count of how many times a process code of 20 has a LastModifiedTime before a process code of 10 for each WorkflowId grouping.
This query shows the table layout and some data:
SELECT TOP 10 *
FROM master.ProcessLogging with (nolock)
WHERE ProcessCode = 10 OR ProcessCode = 20
ORDER BY WorkflowId, ProcessCode

I’ve tried a few things, but I’m having a difficult time getting it to work. Each attempt has lead to a dead end that’s not worth posting here. Is there a way to see all of the times a 20 comes before a 10? And maybe even see the time difference between them?
Upon review this will break if more than one 10 in a group
Will there ever be more than 10 in a group and if so how do you want it handled?
— Edit from Bob Horn —
Slightly modified above query to show the largest time difference between the 10s and 20s.