Skip to content
Advertisement

Find all records that never had status = SUCCESSFUL

I have some processes running within the backend and we are logging it in DB with its status. Now I need to find all processes that never ran successfully since last month.

Example table:

Condition:

  • I am running a query on 16-06-2021
  • To Find only failed PIDs last month (16-06-2021 to 16-05-2021)

Expected Result:

  • PID 1 and PID 3

My try:

  • Tried to get the count of status for each PID and then findings record having 1 count and failed status. But it did not work.

Advertisement

Answer

You want all PIDs that have no ‘SUCCESSFUL’ in the last ~30 days. To find them, aggregate per PID and make sure you don’t find such a row for it.

If you want to add a counter for the failures in the date range:

If on the other hand, you want to restrict this to PIDs that have entries in the last ~30 days, move the date range condition to WHERE:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement