题解 | 查询连续入住多晚的客户信息?
查询连续入住多晚的客户信息?
https://www.nowcoder.com/practice/5b4018c47dfd401d87a5afb5ebf35dfd
with
tb as (
Select
user_id,
ct.room_id,
room_type,
day(checkin_time) din,
day(checkout_time) dout
From
checkin_tb ct
left join guestroom_tb gt on ct.room_id = gt.room_id
)
SELECT
user_id,
room_id,
room_type,
(dout - din) as days
From
tb
Where
(dout - din) > 1
order by days,room_id,user_id desc