这题比较容易,就是难在排序了,需要多注意 with tiaojian as ( select user_id, cb.room_id, room_type, sum(datediff(checkout_time,checkin_time)) as pdiff from checkin_tb cb left join guestroom_tb tb on cb.room_id=tb.room_id where date(checkin_time)>="2022-06-12" group by room_id,room_type,user_id ) select user_id, room_id, room_type, pdiff as days from tiaojian where pdiff>1 order by days ,room_id,user_id desc