I'm trying to build a select query using sqlalchemy, but I need to sort the results by a calculated value and I'm not sure how to do it.
Basically, I have a 'start_time' and 'end_time' columns and I want to order the results based on start_time and then end_time but if end_time < start_time I want to add 86400000 to it:
end_time + (86400000 if end_time < start_time else 0)
I can't figure out how to do it. Is there any simple way to add a calculated property to my table class and have the query retrieve that property?
I've tried using @property to create a getter for that calculated end_time but it didn't work.