Prioritizing values in select statement in ORACLE
If I have well understood your question, you should use the DECODE function in your query in the SELECT and GROUP BY sections.

NB: for performance purpose, you might create an index using that function.