题解 | 查询连续入住多晚的客户信息?
查询连续入住多晚的客户信息?
https://www.nowcoder.com/practice/5b4018c47dfd401d87a5afb5ebf35dfd
with checkin_days as (
select room_id,user_id , (case when day(checkout_time)-day(checkin_time)>1 then day(checkout_time)-day(checkin_time) end) as days from checkin_tb
)
select user_id, cd.room_id ,room_type ,days from checkin_days cd join guestroom_tb g on cd.room_id=g.room_id where days is not null order by days ,room_id ,user_id desc
