I have a table of Sessions. Each session has "session_start_time" and "session_end_time". While the session is open, the end time is empty. I want to fetch the list of sessions, and order it by the following logic:
- If the session is open (no end time), order by the start time.
- If the session is closed, order by the end time.
Something like:
ORDER BY (session_end_time == null) ? session_start_time : session_end_time
I'm using JPA and JPQL for the queries, and using Hibernate for the execution. What would you recommend?
NOTE: I would rather not add CASE to the SELECT, but instead keep it clean so I get a list of sessions without additional unneeded fields.