I am trying to find unfinished tasks within a PostgreSQL table of tasks based on criteria.
The table contains information on the task number, step within a task, type, workplace, time and operator. The task is considered finished when all operators finished. What I specifically need to achieve is a query result that would show all relevant rows for a task and within it the rows that only exist with a "start" code. Example follows:
Task number Step Code Type Workplace Operator Time
5006302212 10 Start PPBG M7UF-110 18003461 05:55:14
5006302212 10 Start PPBG M7UF-110 18002838 05:59:56
5006302212 10 Stop PPBG M7UF-110 18002838 13:59:23
5006302212 10 Start PPBG M7UF-110 18003460 05:55:04
From this example I see that task 5006302212 and its step 10 was started (code Start) by 3 operators. One of them already finished (code Stop). What I need is to get this table:
Task number Step Code Type Workplace Operator Time
5006302212 10 Start PPBG M7UF-110 18003461 05:55:14
5006302212 10 Start PPBG M7UF-110 18003460 05:55:04
I tried using EXCEPT for a query of Stop code but that won't help as it returns the row with Start code for operator that already finished.
Any help will be appreciated.