I have a table similar to this:
incident_id action action_date
----------- ------ -----------
1 A 2012-12-01
2 A 2012-12-01
2 Z 2012-12-02
3 A 2012-12-03
3 Z 2012-12-04
3 G 2012-12-05
In the real table there are many more actions and the dates are datetimes.
Here is the result I want:
incident_id color
----------- -----
1 GREEN
2 RED
3 BLUE
I’m not sure how to accomplish this, I’m weak with SQL in general.
Oops, sorry for not explaining the colors. Ok if an incident has action A then its green. Action B trumps A and the color then becomes red. And once again action C trumps the others and the color is blue.
You can join onto a (either permanent or derived) table that maps ranks to actions and find the
MAX