I have a view that looks like this:
package_id package_line status_a status_b
1 1 NOT_STARTED FAILED
1 2 STARTED STARTED
1 3 FAILED NOT_STARTED
2 1 COMPLETE STARTED
2 2 COMPLETE NOT_STARTED
and so on, for several thousand rows. Status_a and status_b are separate unrelated statuses (in fact they are whether a package executed on system a and on system b).
I need a summary by package_id, to roll up to
package_id status_a status_b
1 FAILED FAILED
2 COMPLETE NOT_STARTED
The rules for combining package lines are
1. If any package line has failed, the package has failed.
2. If all package lines are complete, the package is complete.
3. If all package lines are NOT_STARTED, the package has not started.
4. Otherwise, the package is started (i.e. a combination of started, not_started, and complete would summarize as STARTED).
So I’m trying to come up with a query to create this summary. I’d love to post a code sample, but I’m really at loss. Presumably I want to GROUP_BY the package_id, but what can I use as an aggregate function that would allow me to apply the rules listed?
If it helps, I do have control over how the statuses are reported at the package line level, so I could report a numeric status (though I like having it human readable just for sanity).
Try this (same for
status_b):