select a.user_id, a.room_id, b.room_type, a.days from ( select user_id, room_id, datediff(checkout_time,checkin_time)days from checkin_tb where datediff(checkout_time,checkin_time)>=2 )a join guestroom_tb b on a.room_id=b.room_id order by days, room_id, user_id desc ;