题解 | #查询连续入住多晚的客户信息?#
查询连续入住多晚的客户信息?
https://www.nowcoder.com/practice/5b4018c47dfd401d87a5afb5ebf35dfd
SELECT ct.user_id,
ct.room_id,
gt.room_type,
DATEDIFF(ct.checkout_time, ct.checkin_time) AS days
FROM checkin_tb AS ct
LEFT JOIN guestroom_tb AS gt
ON gt.room_id = ct.room_id
WHERE ct.checkin_time >= '2022-06-12' AND DATEDIFF(ct.checkout_time, ct.checkin_time) > 1
GROUP BY ct.user_id, ct.room_id, gt.room_type, days
ORDER BY days, ct.room_id, ct.user_id DESC;
网易游戏公司福利 643人发布
