select a.user_id, a.room_id, b.room_type, a.days as days from( select room_id, user_id, datediff(checkout_time,checkin_time) as days from checkin_tb ) a join guestroom_tb b on a.room_id = b.room_id where days>1 order by days,room_id,user_id desc 使用子查询实现