mysql - SQL special sort order under certain circumstances -
i have next scenario:
i have list back upwards tickets every back upwards ticket has number of messages (with own datetimes) every ticket has status (open, customerresponded, waitingforcustomer, closed)the whole table should sorted fictional priority, means:
open , customerresponded have same priority, these items sorted datetime of latest ticket message asc (longest untouched ticket should processed first, on top of list). waitingforcustomer has lower priority. tickets waitingforcustomer behind ones status open or customerresponded, , sorted datetime desc (since old ticket client never replied less relevant). closed works same waitingforcustomer has lower priority, tickets @ end of list. so, after explained scenario, have next question:
is possible add together conditions order create possible, or there other way implement that?
edit: ticket status integer (open = 0, customerresponded = 10, waitingforcustomer = 20, closed = 100).
you can utilize case statement within order by:
order status, case when status in (0, 10) datetime end asc, case when status in (20, 100) datetime end desc mysql sql sorting
No comments:
Post a Comment