I have a log for documents that go through my application. The log looks like this:
TABLE: log
==================================================
| log_id | document_id | status_code | timestamp |
==================================================
| 1 | 10 | 100 | 12345 |
--------------------------------------------------
| 2 | 10 | 200 | 23456 |
--------------------------------------------------
I need a list of document_id that have been “stuck” in a certain status_code for a given duration (say 10 minutes; timestamp is Unix timestamp, btw). If a particular document_id is “stuck” in a certain status_code, that status_code will be the last status_code for that document_id.
How do I query this? The 2 things I’m not sure of:
- How do I check if the document has been in a certain status for a certain period of time? I’m guessing I can use some sort of function/formula in my SQL (e.g.
now– 10 minutes), but I don’t know how to do that. - How do I check the duration of only the last status code?
1 Answer